Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have created an ASP.NET project in Visual Studio. The database is a SQL Server Express database TestDB.mdf. I uploaded this with .ldf file to the standard App_Data directory but the connection string doesn't seem to work. How can I use this SQL Server Express database in a shared hosting environment?

My Connection String is:

Data Source=.\\SQLEXPRESS;
Initial Catalog=C:\\inetpub\\dir1\\dir2\\docs\\App_Data\\Test.mdf;
Integrated Security=SSPI;
Connect Timeout=120";

It gives always the same error:

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)

share|improve this question
add comment

2 Answers

Most hosting companies are going to want you to connect to a database server. Having the database on the web server is more for development ease, not for production.

share|improve this answer
3  
And just to add, please don't use the deprecated User instance and AttachDbFileName syntax when you move the database to the web server. <shudder> –  Aaron Bertrand Feb 10 '13 at 20:36
    
@MarkStorey-Smith but still it will require a proper instance of SQL Server being present, so why not do it the right way and actually attach the database instead of this hokey reference-a-file stuff? Especially since most users who do that are surprised when two users of the app have two copies of the database open... –  Aaron Bertrand Feb 11 '13 at 1:32
1  
@Mark but when the app is in production, a new instance of the database is highly unlikely to be what anybody wants. That feature is for development. –  Aaron Bertrand Feb 11 '13 at 11:58
1  
@AaronBertrand Acknowledge that assuming someone can differentiate between when its appropriate and not is risky business. Will remove the suggestion. Hadn't logged that it had been deprecated either... presumably because too many people were doing exactly this :) –  Mark Storey-Smith Feb 11 '13 at 14:26
add comment

The reason this works in Development is because Visual Studio has the ability to host the database contained within the solution - essentially acting as a single connection only version of SQL Express. When you deploy your Application to a Web Server there is nothing on there (by default) that has the ability to do this - as such ASP.NET/IIS does not know what to do with the file - hence why you cannot establish a connection. To connect to the database you must host it on an instance of SQL Server, whether that be SQL Express or a fully fledged version. Whether you should put your database on the same server as IIS is another issue altogether.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.