Click here to Skip to main content
15,900,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,
i use this connection string

C#
string sip = serverIP.Text;
            SqlConnection connection = new SqlConnection("network library = dbmssocn ; Data Source=" + sip + " ;Initial Catalog= Parking_Database ;Integrated Security=True");
            connection.Open();


but when run program this error shown :

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)

what the problem ???
Posted

1 solution

Difficult (if not impossible) to tell from that information.

So, fix it yourself! The first thing to do is to find out exactly what string you are using: so change your code slightly:
C#
string sip = serverIP.Text;
string strCon = "network library = dbmssocn ; Data Source=" + sip + " ;Initial Catalog= Parking_Database ;Integrated Security=True";
SqlConnection connection = new SqlConnection(strCon);
connection.Open();

either use the debugger to examine the content of the "strCon" variable immediately before the new SqlConnection is created, or log it to an output where you can read it later - a log file, or teh console is fine.
Then, try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.

Compare that to the string you are using, and the problem may become clearer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900