C# – A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found,etc

cconnection-stringpublishvisual studio 2010

I'm just publishing my website to my domain name and when I try to access it in my browser I get the Following 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)

I think the problem is into my connection String ==>

<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="TennisOnlineContext" connectionString="Data Source=|DataDirectory|Tennis.sdf" providerName="System.Data.SqlServerCe.4.0 " />
</connectionStrings>
...
</configuration>

Sorry but it's my first web site where I try to publish… So, please what I'm doing wrong ? Thanks in advance…

Best Answer

Have you tried localhost\SQLEXPRESS? Ensure all of your connection keywords abide by those outlined by Microsoft here.

You can check if a connection string is valid, or indeed build a valid connection string that you can copy, by using the SQL/Database Connection utility that ships with VS2010. In VS2010 goto Tools, Connect to database. This will launch the connection dialog; here you can build and test connection strings. For advance connection features, once in the dialog click Advanced. From the advance dialog you can copy and paste connection strings.

Microsoft have also released this dialog to be freely used and distributed in .NET applications. If you interested in this it can be found here.

I hope this helps.

Related Topic