0

I'm developing a VB.NET windows service which connects with some SQL databases. When I try to start the windows service it throws me these errors in the windows event viewer.

ERROR 1

Service cannot be started. System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'EDGEMAN\STLWKSENG11$'.
   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 us...

ERROR 2

Service cannot be started. System.Data.SqlClient.SqlException (0x80131904): Cannot open database "TestTable1" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\SYSTEM'.
   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, DbCo...

I have researched about this errors and read bunch of articles about giving permissions and gave almost all the permissions and tried doing almost every method what they were saying, no luck.

Furthermore detailed version of what I've tried : First I've tried to connect the network databases and then it gave me the below error

Service cannot be started. System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found
   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.CreateConnectio...

Since I thought maybe the issue is with network, I tried to connect local databases just to make sure nothings wrong with the code I wrote. Ended up with the Error1, Error2 which shown above.

SQL Server Logs throws this message : Login failed for user 'EDGEMAN\STLWKSENG11$'. Reason: Could not find a login matching the name provided. [CLIENT: 10.0.15.118]

Appreciate very much your time and consideration all!

Ashan Glenn
  • 27
  • 10
  • I would look at the SQL Server logs and see what the true authentication error is. If you don't understand that error, then put that in your question. – Thom A Apr 08 '21 at 15:33
  • Sure, thanks for that idea @Larnu. This is the error shows at SQL Server logs : "Login failed for user 'EDGEMAN\STLWKSENG11$'. Reason: Could not find a login matching the name provided. [CLIENT: 10.0.15.118]" Also I will edit the question and add it too :) – Ashan Glenn Apr 08 '21 at 15:49
  • So does a server login exist for those credentials and does it have a login for the database specified in the connecrtion string (testable1 seems an odd name for a database) – Stu Apr 08 '21 at 15:53
  • So what don't you understand about that error, @AshanGlenn ; it's pretty explicit. – Thom A Apr 08 '21 at 16:00
  • @Larnu, well yes the error is pretty explicit but I tried adding permissions, googled that error as well. Did everything I know of to gain access but still does not work. Sorry my dumb brain cannot think something else to make this work :/ – Ashan Glenn Apr 08 '21 at 16:14
  • So how did you try to `CREATE` the needed `LOGIN` (and associated `USER`)? What permissions did you give the `LOGIN`/`USER`? What were *those* errors you got and when? Sounds like you should be talking to your DBA to create the needed principles for the AD account. – Thom A Apr 08 '21 at 16:14
  • I've tried following steps STLEDGSQL01 --> Security --> Logins --> Add new login --> Added my PC name as login name "EDGEMAN\STLWKSENG11" , select "SQL Server authentication" as the option, select 115DEV as the default database and finally when I hit OK it gives me this error 'EDGEMAN\STLWKSENG11' is not a valid name because it contains invalid characters. (Microsoft SQL Server, Error: 15006) – Ashan Glenn Apr 08 '21 at 16:24
  • Are you confusing sql server and windows logins. Your login name is a `domain account` not a sql login. – Stu Apr 08 '21 at 17:19
  • Thank you very much guys, I figured out what was the issue. It was actually an issue with windows services page. I had to set up the "Log On" property as "This account" and pass my credentials. Windows service running now :) Appreciate you all! – Ashan Glenn Apr 08 '21 at 18:39

0 Answers0