I created a Windows
service
in Visual Studio 2019. The service works just fine in Visual Studio, but when I deploy it to my local system, the service is now unable to connect to the SQL Server database.
I get this error:
Description: Service cannot be started. System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'GLOADMIN'.
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)
I was initially using Windows authentication, before I changed to SQL Server authentication, both worked in Visual Studio but after deployment as a service on my local Windows 10 system, it fails.
Hi
@adnanabbas99j
, welcome to Microsoft Q&A! Could you please check
Error Log
which Erland mentioned to get more error details? And here have some references might be helped:
Problem to connect windows service to sql server
Windows Service SQL Server error - “Login failed for user”
Look in the SQL Server errorlog. There you find more detailed information about why the login failed.
You find the errorlog in C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\LOG\Errorlog. Note that the exact path depends on your SQL Server version and instance name.
Good day,
Description: Service cannot be started. System.Data.SqlClient.SqlException (0x80131904): Login failed for user...
I was initially using Windows authentication, before I changed to SQL Server authentication, both worked in Visual Studio but after deployment as a service on my local Windows 10 system, it fails.
Note: It is recommended in most cases to use Windows Authentication if this is supported.
More information that could help
is your SQL Server installed in the same machine as the service (the application that connect the server)?
what is your connection string (remove the sensitive information like password)
As other already asked, we need to get the exact full information from the error log file
In the mean time let's play with some guessing, please check if this help you
Make sure that SQL Server is configured to use Mixed mode
Since you are using SQL Authentication now, in the connection string set: Integrated Security=
False