Reputation: 239
I have a problem with my connection string and I couldn't find anything on the web that could help me. So I have a test website on which I connect to a database which is not on the same server. There it all works fine, the data is being read correctly and the connection is successful.
Now when I try the same on a website which is on the same server than the database it doesn't work. So I figured I can't just connect to the database server as I would from a different server if I am already on that server like this:
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=serverName;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
Could anyone help me with that?
If you need more information just ask please.
Thanks in advance!
[edit]
Oh I forgot...this is the error message I get:
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)
Upvotes: 1
Views: 503
Reputation: 11
Both answers above are correct, however, if you have SQL Express installed (I assume we're talking about MS SQL) then your connection string must be something like this:
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
Upvotes: 1
Reputation: 148150
Try localhost
instead of server name
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=localhost;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
Upvotes: 3
Reputation: 18116
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=.;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
Upvotes: 2