Windows 8.1服务无法连接到SQL Server数据库
我有一台服务器连接到运行Windows 8.1的服务器。 它正在运行SQL Server 2014 Express。
我有一个我编写的连接到数据库的C#服务。 不幸的是,当它作为服务安装时,它不会引发下面显示的错误。
我可以运行该应用程序,它可以成功运行,但是当它是服务时,它不起作用。
我已启用TCP / IP。 我可以通过另一台机器上的vpn将管理工作室连接到实例。
这是来自配置文件的连接字符串
<value>Server=localhostMSSQLSERVER2012;Initial CataLog=lms;Persist Security Info=No;Password=pw;User ID=user;Connect Timeout=5</value>
例外:
DomainExceptionHandler捕获:System.Data.SqlClient.SqlException(0x80131904):建立到SQL Server的连接时发生网络相关或实例特定的错误。 服务器未找到或无法访问。 验证实例名称是否正确,并将SQL Server配置为允许远程连接。 (提供程序:SQL网络接口,错误:26 - 指定错误定位服务器/实例)
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection,Action'1 wrapCloseInAction)在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔callerHasConnectionLock,布尔asyncClose)在System.Data.SqlClient.TdsParser .Connect(ServerInfo serverInfo,SqlInternalConnectionTds connHandler,Boolean ignoreSniOpenTimeout,Int64 timerExpire,布尔加密,布尔trustServerCert,布尔integratedSecurity,布尔withFailover)在System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,SecureString newSecurePassword,Boolean ignoreSniOpenTimeout, TimeoutTimer超时,布尔withFailover)在System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,String newPassword,SecureString newSecurePassword,Boolean redirectedUserInstance,SqlConnectionString connectionOptions,SqlCredential凭据,TimeoutTimer超时)在S ystem.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer超时,SqlConnectionString connectionOptions,SqlCredential凭据,字符串newPassword,SecureString newSecurePassword,布尔redirectedUserInstance)在System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity身份,SqlConnectionString connectionOptions,SqlCredential凭据,对象(System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,DbConnectionPoolKey poolKey,对象poolGroupProviderInfo,DbConnectionPool池,DbConnection拥有连接,DbConnectionOptions userOptions)上的提供程序providerInfo,字符串newPassword,SecureString newSecurePassword,布尔redirectedUserInstance,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData) .ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool池,DbConnection owningObject,DbConnectionOptions选项,DbConnectionPoolKey poolKey,DbConnection (System.Data.ProviderBase)上的System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)上的System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)中的选项userOptions) System上的System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource'1重试,DbConnectionOptions userOptions,DbConnectionInternal&connection)上的DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal&connection) Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource'1 retry,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbConnectionInternal&connection)在S ystem.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重试)在System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource'1重试)在System.Data.SqlClient.SqlConnection.Open()在LMS.Core.Environment。 SQLDeviceStateWriterProvider.SQLDeviceStateWriter.writeState(DateTime timestamp)
对不起,这是我的错。 连接字符串未被正确调用。
链接地址: http://www.djcxy.com/p/56711.html上一篇: Windows 8.1 service can't connect to SQL Server database