简体   繁体   中英

Connecting to SQL server via TCP/IP, not NP

As I found out, my SQL server has disabled Named Pipes, but enabled TCP/IP (and it will stay this way). Now I am trying to connect from the visual studio to the database, but with no luck. I've tried so far:

string connstring = "Data Source=192.168.1.1:1433 ;Initial Catalog=np-sparcsn4-custom;Persist Security Info=True;User ID=xxxx;Password=/*****/";

string connstring = "Data Source=192.168.1.1:1433 ; Network Library=DBMSSOCN; Initial Catalog=np-sparcsn4-custom;Persist Security Info=True;User ID=xxxx;Password=/*****/";

I've tried to replace the IP address with name - no luck. When I try to connect using the table adapter I can preview the data, same if I'd use ie grid - but in the code I simply can't open connection to it: I always have Network related or server specific error, usually its either

Named Pipes Provider: Could not open a connection to SQL Server [5] 

or

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server

Server is set up to accept remote connection and it is accessible.

Update:

I've tried

string connstring = "Server=tcp:192.168.1.1,1433 ;Initial Catalog=np-sparcsn4-custom;Persist Security Info=True;User ID=xxx;Password=/****/";

or

"Server=tcp:ponln4report,1433 ....

and I've got error:

provider: TCP Provider, error: 0 - A non-recoverable error occurred during a database lookup**strong text**

在此输入图像描述

在此输入图像描述

EDI2: I've found an older SQL server 2005 that I can connect without a problem. It is a bit of a pain because it lacks ie Date and Time data types, but I guess it has to do for now.

For C#, use this connection string

connectionString="Data Source=192.168.1.1,1433;Initial Catalog=np-sparcsn4-custom;Integrated Security=false;User ID=your_username;Password=your_password"

If you need to modify a web.config file, add this node:

<connectionStrings>
        <remove name="LocalSqlServer" />
        <add name="LocalSqlServer" connectionString="Data Source=192.168.1.1,1433;Initial Catalog=np-sparcsn4-custom;Integrated Security=false;User ID=your_username;Password=your_password" providerName="System.Data.SqlClient" />
    </connectionStrings>

确保SQL Configuration Manager -> Protocols中的端口1433设置为IPALL SQL Configuration Manager -> Protocols SQLEXPRESS SQL Configuration Manager -> Protocols 屏幕截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM