我的C#应用程序无法连接到我的SQLServerExpress
实例。
使用我的连接字符串中的localhost\SQLExpress
或<servername>\SQLExpress
运行应用程序可在服务器上本地运行,但不能从网络中的其他主机上运行。
1433
添加了防火墙规则。AllowRemoteConnection
设置为true
。我仍然收到SqlException
的话:
System.Data.SqlClient.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.
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)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
还有什么需要检查的吗?
更新#1:
PS C:\Windows\system32> Get-Process -Name sqlservr
| Select-Object -ExpandProperty ID
| ForEach-Object {Get-NetTCPConnection -OwningProcess $_ -state LISTEN
| select LocalAddress, LocalPort, RemoteAddress, RemotePort, State}
LocalAddress : ::
LocalPort : 58956
RemoteAddress : ::
RemotePort : 0
State : Listen
LocalAddress : ::
LocalPort : 1433
RemoteAddress : ::
RemotePort : 0
State : Listen
LocalAddress : 0.0.0.0
LocalPort : 58956
RemoteAddress : 0.0.0.0
RemotePort : 0
State : Listen
LocalAddress : 0.0.0.0
LocalPort : 1433
RemoteAddress : 0.0.0.0
RemotePort : 0
State : Listen
答案 0 :(得分:0)
尝试一下:
转到SQL Server配置管理器(Win + R => SQLServerManager10.msc或SQLServerManager.msc)
单击“ SQL网络服务”并导航到有关的服务器。
为基于IP的Conn(或)命名连接(使用服务器名称)启用TCP / IP协议
重新启动SQL Server并检查