Connection Exection frim Windows SERVICE

E

Evan Camilleri

I am getting an exeception when I access an SQL database (on another
machine) from a 'Windows Service'. The same code works if the SQL Server is
local or code is in a Windows Application.

Following is exception from Event Viewer:


Event Type: Error
Event Source: TestServ
Event Category: None
Event ID: 0
Date: 05/11/2004
Time: 11:22:22 AM
User: N/A
Computer: VOYAGER
Description:
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)

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
 
J

Jim Hughes

Configure the service to run as a domain account instead of LocalSystem

LocalSystem does not have access to network services.
 
E

Evan Camilleri

I tried still in vain:

Sql Connection = Data Source=(local);DataBase=CRM;Integrated Security=SSPI;
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 '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)

OR

Sql Connection = Data Source=(local);DataBase=CRM;Integrated
Security=False;User ID=sa;Pwd=nexus;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)

= = = = = = = = = = = = = = = = = = = = = = = = = = = = =


Jim Hughes said:
Configure the service to run as a domain account instead of LocalSystem

LocalSystem does not have access to network services.

Evan Camilleri said:
I am getting an exeception when I access an SQL database (on another
machine) from a 'Windows Service'. The same code works if the SQL Server
is local or code is in a Windows Application.

Following is exception from Event Viewer:


Event Type: Error
Event Source: TestServ
Event Category: None
Event ID: 0
Date: 05/11/2004
Time: 11:22:22 AM
User: N/A
Computer: VOYAGER
Description:
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)

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
 
J

Jim Hughes

You said in your first message "The same code works if the SQL Server
is local or code is in a Windows Application", since you didn't supply your
connection string until this reply, I didn't see that you were still using
Data Source=(local).

If in fact, it is a remote SQL server, then you need to change Data
Source=(local) to Data Source=remoteservername or Data
Source=remoteservername\instancename.


Evan Camilleri said:
I tried still in vain:

Sql Connection = Data Source=(local);DataBase=CRM;Integrated
Security=SSPI;
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 '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)

OR

Sql Connection = Data Source=(local);DataBase=CRM;Integrated
Security=False;User ID=sa;Pwd=nexus;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)

= = = = = = = = = = = = = = = = = = = = = = = = = = = = =


Jim Hughes said:
Configure the service to run as a domain account instead of LocalSystem

LocalSystem does not have access to network services.

Evan Camilleri said:
I am getting an exeception when I access an SQL database (on another
machine) from a 'Windows Service'. The same code works if the SQL Server
is local or code is in a Windows Application.

Following is exception from Event Viewer:


Event Type: Error
Event Source: TestServ
Event Category: None
Event ID: 0
Date: 05/11/2004
Time: 11:22:22 AM
User: N/A
Computer: VOYAGER
Description:
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)

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
 
E

Evan Camilleri

Yes I was doing it!

The problem was stiupid. The database is named CRM on the localhost and
CRM2003 on the server

:(

Maybe as message Database not found would have been more ideal instead of
login fails!


Thanks anyway.

Evan


Jim Hughes said:
You said in your first message "The same code works if the SQL Server
is local or code is in a Windows Application", since you didn't supply
your connection string until this reply, I didn't see that you were still
using Data Source=(local).

If in fact, it is a remote SQL server, then you need to change Data
Source=(local) to Data Source=remoteservername or Data
Source=remoteservername\instancename.


Evan Camilleri said:
I tried still in vain:

Sql Connection = Data Source=(local);DataBase=CRM;Integrated
Security=SSPI;
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 '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)

OR

Sql Connection = Data Source=(local);DataBase=CRM;Integrated
Security=False;User ID=sa;Pwd=nexus;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)

= = = = = = = = = = = = = = = = = = = = = = = = = = = = =


Jim Hughes said:
Configure the service to run as a domain account instead of LocalSystem

LocalSystem does not have access to network services.

I am getting an exeception when I access an SQL database (on another
machine) from a 'Windows Service'. The same code works if the SQL
Server is local or code is in a Windows Application.

Following is exception from Event Viewer:


Event Type: Error
Event Source: TestServ
Event Category: None
Event ID: 0
Date: 05/11/2004
Time: 11:22:22 AM
User: N/A
Computer: VOYAGER
Description:
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)

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top