當我用management studio訪問數據庫時,一切正常,我訪問表......但是當我運行用相同用戶訪問數據庫的Windows服務時,會引發此錯誤。無法打開登錄請求的數據庫<database>。登錄失敗。登錄失敗的用戶<user>
System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Cannot open database "sttcoletorsbvt" requested by the login. The login failed.
Login failed for user 'usr_stt_coletor'.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
--- End of inner exception stack trace ---
at DynamicModule.ns.Wrapped_IServicoConfiguracaoColetor_3f81c81b8be24d3998bbc85dfa25d87f.SelecionarConfiguracao()
at Infraero.TINE3.STTColetor.Negocio.Coletor.ColetarBilhetes(String arquivoParaProcessar)
at Infraero.TINE3.STTColetor.WindowsService.ManipuladorBilhetes.RealizarProcedimentoColeta(String caminhoArquivo)
at Infraero.TINE3.STTColetor.WindowsService.ServicoColetor.RealizarColeta()
我該如何解決這個問題?
您是否檢查過您是否在Windows服務中傳遞了與您登錄管理工作室時相同的確切密碼? – 2013-03-22 18:41:07
是的,我使用app.config的副本/粘貼進行登錄。 – 2013-03-22 18:45:18
可能將不得不分享你用來連接的代碼。還評論一下,如果這個SQL身份驗證或Windows身份驗證?並且是錯誤中提到的數據庫,您嘗試連接到的數據庫。還要確保你連接到正確的服務器等等。 – 2013-03-22 18:52:10