简体   繁体   English

通过TCP / IP连接到SQL服务器,而不是NP

[英]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). 我发现,我的SQL服务器已禁用命名管道,但启用了TCP / IP(它将保持这种方式)。 Now I am trying to connect from the visual studio to the database, but with no luck. 现在我正在尝试从visual studio连接到数据库,但没有运气。 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. 我试图用名字替换IP地址 - 没有运气。 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 当我尝试使用表适配器连接时,我可以预览数据,如果我使用ie网格也一样 - 但在代码中我根本无法打开它的连接:我总是有网络相关或服务器特定的错误,通常是或

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. EDI2:我发现了一个旧的SQL Server 2005,我可以毫无问题地连接。 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 对于C#,请使用此连接字符串

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: 如果需要修改web.config文件,请添加以下节点:

<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 屏幕截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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