Peter Morris
Peter Morris

Reputation: 23224

SQL Server 2005 and APP_DATA

I was once told that instead of having to have my host register a SQL Server database file + user/password it is possible instead to put my MDB file into my website's APP_DATA and connect to it directly. How do I do this?

I tried using the SqlConnection's connection wizard and set DataSource : Microsoft SQL Server Database File (SqlClient) Database file name : Path to a non-existent file in my App_Data folder. Authentication : (tried both windows and SQL server)

I click OK, at which point I am asked if I wish to create the file or not, I select "Yes". Then I experience this message:


Microsoft Visual Studio


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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)


OK


I have SQL Server 2005 installed. Is there something I am missing?

Upvotes: 1

Views: 264

Answers (2)

John Christensen
John Christensen

Reputation: 5030

Off-hand, I think what they're talking about is MS SQL Express.

Upvotes: 1

Jeremy
Jeremy

Reputation: 1208

I hope you mean .MDF file?

The full path to the filename is in the connection string. Something like:

Server=localhost;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;

Upvotes: 2

Related Questions