2011-01-06 33 views
2

我正在支持一箇舊的vb.net程序,它的數據庫連接到的數據庫已從SQL Server 2005遷移到SQL Server 2008.在SQL Server 2008中是否有一個允許ODBC連接訪問數據庫但不允許VB的設置。 NET以編程方式連接到它?爲什麼我可以通過odbc而不是通過vb.net代碼連接到sql server 2008?

我不斷收到在應用程序中的錯誤是:

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)

不過,我可以連接到它,當我創建一個系統DSN SQL Server實例,並通過VS2005的工具>>連接到數據庫。

這裏是我使用的連接代碼:

dim strC as string 
strC = "data source=bob; database=subscribers; user id=bobuser; password=passme" 
dim connection as New SqlClient.SqlConnection(strC) 
try  
    connection.open() 
catch ex as Exception  
    msgbox(ex.message) 
end try 
connection.Close() 

回答

2

沒有這樣的設置,但因爲它是可能的:您可以通過ODBC訪問您的服務器,因爲使用ODBC DSN創造了某種到服務器的本地網橋。嘗試從VB.NET代碼連接到服務器與SqlClient庫從客戶機需要您的Sql Server接受遠程連接...

請檢查此MSDN article尋求幫助。

簡單:

  • 您需要設置SQL Server以允許遠程連接
  • 你需要確保你的防火牆沒有阻止SQL Server的端口(S)
  • 確保TCP/IP作爲通信啓用。機構對於SQL Server
+0

將開發在VS2005 Windows應用程序連接到SQL Server 2008數據庫與使用VS2010有什麼不同? – phill 2011-01-07 06:00:31

1

開始>運行> 「CLICONFG」(不含引號)

在SQL Server客戶端網絡實用工具,啓用TCP/IP命名管道