應用程序加載,但是當應用程序嘗試建立與SQL的連接時,加載需要一段時間,然後返回錯誤。使用DataLink(.udl文件)測試連接屬性時,它是成功的。該應用程序在我的本地機器上運行良好。我到處搜索,設置都很好,網絡管理員驗證了防火牆,並且所有設置都正確。我錯過了什麼?將應用程序發佈到遠程服務器時連接到SQL的問題
我注意到它提到錯誤中的名稱管道,但是,不應該這使得TCP?
SQLConnectionString.NetworkLibrary = "dbmssocn";
這是我的連接字符串的方法:
public string GetReachoutConnectionString()
{
SqlConnectionStringBuilder SQLConnectionString = new SqlConnectionStringBuilder();
SQLConnectionString.TypeSystemVersion = "Latest";
SQLConnectionString.NetworkLibrary = "dbmssocn";
SQLConnectionString.DataSource = "10.10.xxx.xx,1433";
SQLConnectionString.InitialCatalog = "cat";
SQLConnectionString.UserID = "xxx";
SQLConnectionString.Password = "xxx";
SQLConnectionString.MultipleActiveResultSets = true;
SQLConnectionString.ApplicationName = "Website";
return SQLConnectionString.ConnectionString;
}
這是我收到的錯誤:
[Win32Exception (0x80004005): The network path was not found]
[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct 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.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +1394
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +1120
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +70
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +964
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +114
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1631
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +117
1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +267
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) +318
1 retry) +211
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +393 System.Data.SqlClient.SqlConnection.Open() +122
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +177
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +182
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +123
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +2964
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +369 System.Web.UI.WebControls.ListControl.PerformSelect() +43
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +139 System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +36
System.Web.UI.Control.PreRenderRecursiveInternal() +107
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.Control.PreRenderRecursiveInternal() +204
System.Web.UI.d__249.MoveNext() +1400 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13847892
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61
System.Web.Util.WithinCancellableCallbackTaskAwaiter.GetResult() +32
System.Web.UI.d__523.MoveNext() +9283
也許遠程服務器不支持'NamePipes'你可以使用實際的sqlserver數據庫名稱等連接到它..看看[連接字符串Sql服務器](https://www.connectionstrings.com/sql-服務器/) – MethodMan
我不想使用名稱管道。爲什麼它認爲我正在努力?我正嘗試使用tcp進行連接。我已經檢查過,它們都已啓用。 –
,因爲你編碼它在這裏查找IP地址/名字管道這裏'SQLConnectionString.DataSource =「10.10.xxx.xx,1433」;'閱讀我之前發表的關於如何在C#中使用C#配置連接字符串的評論SQL Server .. – MethodMan