E
Evan Camilleri
I am getting a connection exception when trying to access an SQL Server
which is NOT localhost through a Windows SERVICE. Following are the
situations:
(1) DOES NOT WORK: Windows SERVICE
Windows Service
Sql Connection = Data Source=ENTERPRISE;DataBase=CRM;Integrated
Security=SSPI;
Service Log on As = HOLISTIC\evan
Exception:
TestServ raised an Exception: System.Data.SqlClient.SqlException: Cannot
open database requested in login 'CRM'. Login fails.
Login failed for user 'HOLISTIC\evan'.
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
at TestWindowsService.TestServ.OnStart(String[] args)
(2) DOES NOT WORK: Windows SERVICE
Sql Connection = Data Source=ENTERPRISE;DataBase=CRM;Integrated
Security=False;User ID=sa;Pwd=***;Persist Security Info=False;
Service Log on As = HOLISTIC\evan
TestServ raised an Exception: System.Data.SqlClient.SqlException: Cannot
open database requested in login 'CRM'. Login fails.
Login failed for user 'sa'.
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
at TestWindowsService.TestServ.OnStart(String[] args)
(3) The above code will work if it is executed as Windows APPLICATION or
even as Windows SERVICE if the SQL Server is localhost.
which is NOT localhost through a Windows SERVICE. Following are the
situations:
(1) DOES NOT WORK: Windows SERVICE
Windows Service
Sql Connection = Data Source=ENTERPRISE;DataBase=CRM;Integrated
Security=SSPI;
Service Log on As = HOLISTIC\evan
Exception:
TestServ raised an Exception: System.Data.SqlClient.SqlException: Cannot
open database requested in login 'CRM'. Login fails.
Login failed for user 'HOLISTIC\evan'.
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
at TestWindowsService.TestServ.OnStart(String[] args)
(2) DOES NOT WORK: Windows SERVICE
Sql Connection = Data Source=ENTERPRISE;DataBase=CRM;Integrated
Security=False;User ID=sa;Pwd=***;Persist Security Info=False;
Service Log on As = HOLISTIC\evan
TestServ raised an Exception: System.Data.SqlClient.SqlException: Cannot
open database requested in login 'CRM'. Login fails.
Login failed for user 'sa'.
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
at TestWindowsService.TestServ.OnStart(String[] args)
(3) The above code will work if it is executed as Windows APPLICATION or
even as Windows SERVICE if the SQL Server is localhost.