【问题标题】:Connecting to SQL server via TCP/IP, not NP通过 TCP/IP 而不是 NP 连接到 SQL 服务器
【发布时间】:2014-10-07 22:19:46
【问题描述】:

我发现,我的 SQL 服务器禁用了命名管道,但启用了 TCP/IP(它将保持这种状态)。现在我正在尝试从视觉工作室连接到数据库,但没有运气。 到目前为止我已经尝试过:

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=/*****/";

我尝试用名称替换 IP 地址 - 不走运。当我尝试使用表适配器进行连接时,我可以预览数据,如果我使用即网格也是如此 - 但在代码中我根本无法打开与它的连接:我总是有网络相关或服务器特定错误,通常是它要么

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

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

服务器已设置为接受远程连接并且可以访问。

更新:

我试过了

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

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

我有错误:

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

EDI2:我找到了一个较旧的 SQL Server 2005,我可以毫无问题地连接。这有点痛苦,因为它缺少日期和时间数据类型,但我想现在必须这样做。

【问题讨论】:

  • 您是否确保 SQL Server 已启用 TCP/IP 并可访问?
  • 是的,它们已启用
  • 查看 SQL Native Client 10.0 配置节点下的内容:是否启用了 tcp/ip?
  • 很抱歉,如果它实际上不是重复的,请关闭您的问题。没想到我的投票会像个banhammer :)
  • 再次启用,问题已更新

标签: c# sql-server sql-server-2008 ado.net connection-string


【解决方案1】:

对于 C#,使用此连接字符串

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

如果需要修改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>

【讨论】:

  • 我试过了。 “数据源”和“服务器”可以互换。
【解决方案2】:

确保在 SQLEXPRESS 的 SQL Configuration Manager -&gt; Protocols 中的 IPALL 中设置 port 1433 screenshot

【讨论】:

  • 不,SQL 可以使用任何端口。 SqlBrowser 会给你正确的
猜你喜欢
  • 2012-12-14
  • 1970-01-01
  • 2018-01-11
  • 2021-04-20
  • 1970-01-01
  • 2017-03-14
  • 2019-01-03
  • 1970-01-01
  • 2015-05-15
相关资源
最近更新 更多