How to solve the system.data.sqlclient.sqlexception (0x80131904) error

0

I've created an application that works perfectly on my PC using C# and SQL Server 2008 R2. My connection string is:

connectionString="Data Source=KELVIN-PC;Initial Catalog=LMS;User ID=sa;Password=temperament"

But I have published it and installed it on another PC. I also copied the LMS.bak file to the PC and restored the database on it MS SQL Server 2008 R2. But whenever it has to connect to the database on the other machine it gives the error below:

System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while extablishing 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).....

I've spent hours searching through the internet but most answered problems have a little difference from my own and some suggestions I have tried didn't really work.

c#
sql
sql-server-2008
asked on Stack Overflow Feb 19, 2014 by KelvinOro • edited May 3, 2018 by Uwe Keim

3 Answers

1

You also need to change the DataSource of the connection string. KELVIN-PC is the name of your local machine and the sql server is running on the default instance.

If you are sure the the server is running as the default instance, you can always use . in the DataSource, eg.

connectionString="Data Source=.;Initial Catalog=LMS;User ID=sa;Password=temperament"

otherwise, you need to specify the name of the instance of the server,

connectionString="Data Source=.\INSTANCENAME;Initial Catalog=LMS;User ID=sa;Password=temperament"
answered on Stack Overflow Feb 19, 2014 by John Woo
1

The datasource is by default .\SQLEXPRESS (its the instance where databases are placed by default) or if u changed the name of the instance during installation of sql server so i advise you to do this :

connectionString="Data Source=.\\yourInstance(defaulT Data source is SQLEXPRESS);
       Initial Catalog=databaseName;
       User ID=theuser if u use it;
       Password=thepassword if u use it;
       integrated security=true(if u don t use user and pass; else change it false)"

Without to knowing your instance, I could help with this one. Hope it helped

answered on Stack Overflow Feb 19, 2014 by Souf • edited Feb 19, 2014 by Souf
0

Well, did you DO what the error says? You go to some length telling about installation, but what about the obvious?

  • Check the other server's network configuration in SQL Server.
  • Check the other machines FIREWALL. SQL Server does not open ports automatically, so the windows firewall normally blocks access..
answered on Stack Overflow Feb 19, 2014 by TomTom

User contributions licensed under CC BY-SA 3.0