0

Good day.

I'm busy with a new website, but I am caught in a slight tangle.

Current folder layout of careers.aspx and database which is detached

How can I set up my data source in my web.config file to access the database listed in App_Data?

Here is what I tried. I am a little rusty with detached databases.

<connectionStrings>
        <add name="Careers" providerName="System.Data.SqlClient" connectionString="AttachdbFilename=../|DataDirectory|/Careers_30March.mdf;user instance=true;Integrated Security=true;"/>
</connectionStrings>

This was my result:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

All I need is to access this database. I know how to read connection strings from the web.config to create a SqlConnection object. No usernames / passwords were allocated to this database.

1 Answer 1

1

Do take a look at this page. There are multiple examples on what can and cannot be used.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks, Ill upvote this because it took me a step forward. Now I'm slammed by The database 'Careers_30March' cannot be opened because it is version 655. This server supports version 612 and earlier. A downgrade path is not supported. Could not open new database 'Careers_30March'. CREATE DATABASE is aborted. Cannot attach the file 'C:\Inetpub\wwwroot\Career\App_Data\Careers_30March.mdf' as database 'Careers_30March'.
@Eon: Take a look at this blog post. Explains that problem in detail.
You see, I don't want it to be bound to a instance, because I'm afraid the connection string will break on the web server once I upload the database. Can you perhaps explain to me how I am to upload my database w/o breaking my website? First time I do a website that would have a database attached to it
It is clear that the webserver that my boss uses is still on the .net framework 2.0 , because it errors out when it read System.Linq , So I'm being careful
Seems like it's for Visual Studio to know which tools to use with the database. As for deploying it, you'd need to contact your hosting provider to find out if they support file based databases. AFAIK, it shouldn't be an issue if they support it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.