Connection SQL Server 2012 via Windows service

0

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, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 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 ClientConnectionId: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

c#
.net
sql-server-2012
windows-services
asked on Stack Overflow Jul 22, 2020 by rayen • edited Aug 27, 2020 by Dale K

1 Answer

0

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;"
answered on Stack Overflow Aug 11, 2020 by rayen

User contributions licensed under CC BY-SA 3.0