我有一個C#程序連接到SQL Server。它工作正常,在測試計算機與SQL Server 2012的,但是對生產環境與2008年在生產環境中無法正常工作,它會報告異常,因爲這樣,無法連接到SQL Server,但Excel和ODBC配置可以
Unhandled Exception: System.Data.SqlClient.SqlException: A network-related or in stance-specific error occurred while establishing a connection to SQL Server. Th e server was not found or was not accessible. Verify that the instance name is c orrect and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) -- -> System.ComponentModel.Win32Exception: Access is denied
這裏是我的連接代碼,
connStrSql = "Server=" + sqlserver + "; Database=" + sqldb + "; Trusted_Connection=True";
SqlConnection sqlConn = new SqlConnection(connStrSql)
sqlConn.Open();
目標平臺是x86,目標框架是4.5。有趣的是,Excel和ODBC配置可以連接到數據庫而不抱怨。 C#程序是否使用連接到SQL Server的不同方式?我該如何解決這個問題?
你連接嘗試連接到SQL Server遠程? –
是的,我應該嘗試不同的網絡庫,如tcp而不是默認的命名管道? – tabasco
好的。 Excel是遠程的還是本地的SQL Server? –