简体   繁体   中英

Connection SQL Server 2012 via Windows service

I created a windows service for monitoring to send data (OS info, proc, ram etc) to my SQL Server database and it works fine on my computer. I already installed the service in another machine that has SQL Server and it can connect to mydatabase successfully but when the service runs it appear those error in service log.

This is my connection string

CONNECTION_STRING = "Server=*******\\SQLEXPRESS;Database=Parc_informatique; User Id=tsi;password=******;";

Also the service run as local user

2020-07-22 15:09:34.7392 - DEBUG: Starting service 2020-07-22 15:09:34.7392 - DEBUG: Callback started 2020-07-22 15:09:34.7392 - DEBUG: Starting sending Data 2020-07-22 15:09:35.1712 - ERROR: System.Data.SqlClient.SqlException (0x80131904): Échec de l'ouverture de session de l'utilisateur ' AUTORITE NT\ANONYMOUS LOGON '. at 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, SqlAuthenticationProviderManager sqlAuthProviderManager) 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, DbConn ectionInternal 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() at SignalRbus.InfoManager.SendData() in C:\Users\Rayen\source\repos\project\SignalRbus\SystemInfo.cs:line 197 at DetailService.Service1.serviceTimer_callback(Object state) in C:\Users\Rayen\source\repos\project\DetailService\Service1.cs:line 45 ClientConnection Id:a19ffe41-1f72-4e44-a883-f4eed400e93e Error Number:18456,State:1,Class:14 ClientConnectionId:00000000-0000-0000-0000-000000000000 Error Number:-1,State:0,Class:20

I solved it by adding Integrated Security=False to the connection string like this

CONNECTION_STRING = "Server=*\SQLEXPRESS;Database=Parc_informatique; User Id=tsi;password=;Integrated Security=False;"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM