2014-10-07 71 views
3

我發現,我的SQL服務器已禁用命名管道,但啓用了TCP/IP(它會保持這種方式)。現在我試圖從Visual Studio連接到數據庫,但沒有運氣。 到目前爲止,我已經試過:通過TCP/IP連接到SQL服務器,而不是NP

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地址 - 沒有運氣。當我嘗試使用表格適配器進行連接時,我可以預覽數據,如果使用ie網格,也是如此 - 但是在代碼中,我根本無法打開連接:我總是遇到與網絡相關的或服務器特定的錯誤,通常是無論是

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** 

enter image description here

enter image description here

EDI2:我發現了一箇舊的SQL Server 2005中,我可以連接沒有問題。這有點痛苦,因爲它缺少日期和時間數據類型,但我猜它現在必須做。

+0

你確定SQL Server具有啓用並可訪問的TCP/IP嗎? – abatishchev 2014-10-07 22:36:27

+0

是的,它們已啓用 – Yasskier 2014-10-07 22:40:28

+0

檢查SQL Native Client 10.0配置節點下的內容:是否啓用了tcp/ip? – Isantipov 2014-10-07 22:40:47

回答

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> 
+0

我試過了。 「數據源」和「服務器」可以互換。 – Yasskier 2014-10-08 21:05:04

0

確保端口1433設置IPALL in SQL Configuration Manager -> Protocols for SQLEXPRESS screenshot

相關問題