Windows 8.1服务无法连接到SQL Server数据库

时间:2014-11-06 00:32:33

标签: c# sql-server windows

我有一台服务器,我正在连接到运行Windows 8.1的服务器。它正在运行SQL Server 2014 Express。

我有一个连接数据库的C#服务。不幸的是,当它作为服务安装时,它不会连接抛出下面显示的错误。

我可以运行该应用程序并且它可以成功运行,但是当它是服务时它不起作用。

我启用了TCP / IP。我可以通过另一台机器上的vpn与管理工作室连接到实例。

这是我的配置文件

中的连接字符串
<value>Server=localhost\MSSQLSERVER2012;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 - 查找指定的服务器/实例时出错)

     

at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,Boolean breakConnection,Action'1 wrapCloseInAction)      在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,Boolean callerHasConnectionLock,Boolean asyncClose)      在System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternalConnectionTds connHandler,Boolean ignoreSniOpenTimeout,Int64 timerExpire,Boolean encrypt,Boolean trustServerCert,Boolean integratedSecurity,Boolean withFailover)      在System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,SecureString newSecurePassword,Boolean ignoreSniOpenTimeout,TimeoutTimer timeout,Boolean withFailover)      在System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,String newPassword,SecureString newSecurePassword,Boolean redirectedUserInstance,SqlConnectionString connectionOptions,SqlCredential credential,TimeoutTimer timeout)      at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout,SqlConnectionString connectionOptions,SqlCredential credential,String newPassword,SecureString newSecurePassword,Boolean redirectedUserInstance)      在System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity标识,SqlConnectionString connectionOptions,SqlCredential凭证,Object providerInfo,String newPassword,SecureString newSecurePassword,Boolean redirectedUserInstance,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData)      在System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbConnectionPool池,DbConnection owningConnection,DbConnectionOptions userOptions)      在System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool池,DbConnection owningObject,DbConnectionOptions选项,DbConnectionPoolKey poolKey,DbConnectionOptions userOptions)      在System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)      在System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)      在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal&amp; connection)      在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource'1 retry,DbConnectionOptions userOptions,DbConnectionInternal&amp; connection)      在System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource'1 retry,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbConnectionInternal&amp; connection)      在System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource'1 retry,DbConnectionOptions userOptions)      在System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource'1 retry,DbConnectionOptions userOptions)      在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)

1 个答案:

答案 0 :(得分:0)

抱歉这是我的错。 连接字符串未正确调用。