views:

1101

answers:

2

I'm trying to connect to a remote SQL Server 2005 db from a .NET Windows service running in Vista Home Premium x64. I can access the remote db from a console app with no problem. I can connect to a local db from the Windows service with no problem. I was able to connect from a service from XP with no problem. There's no firewall or anti-virus running. How do I configure this service to be able to connect to the remote db?

I've tried to connect by running the Windows service as a local admin account, LocalSystem, LocalService, and NetworkService.

The connection string:

Data source=SERVER_NAME;Initial Catalog=DB_NAME;Integrated Security=True;

The error:

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)

MORE INFO:

I have also tried to connect using SQL Server authentication with no success:

Data Source=SERVER_NAME;User ID=USER_ID;Password=PWD;Initial Catalog=DB_NAME

This connection string works from the console app too.

MORE INFO:

I ran Process Monitor for the Windows Service and the console app. The Windows service showed \SERVER_NAME\pipe\sql\query was ACCESS DENIED but the console app showed SUCCESS when reading/writing files to \SERVER_NAME\pipe\sql\query.

A: 

1) open a command prompt. Type "ping SERVER_NAME". Does it respond? You may have a DNS or connectivity issue if this doesn't work.

2) "telnet SERVER_NAME 1443". Do you see anything or does it refuse your connection? This will definitively tell you whether or not someone is listening on the other end.

3) Go into SQL Server Management Studio. Right click Properties of your server. Select "Connections" from the left side. Is "Allow Remote Connections" checked?

4) Since you're running using network service/system, you will need to make sure you have a login configured on your server for the machine account DOMAIN\CLIENTSYSTEMNAME$. Note the $ sign. This is your machine account, and this will be the user that SQL Server will see.

Dave Markle
1. Ping works fine; 2. 1143 doesn't work, 445 looks like it works; 3: Yes; 4: I VPN in to the network and use Win Explorer to go to \\Server, then I login using my network userid/pwd. After that the console app connects to the db fine as does connecting from XP.
TxDeveloper
When you VPN in, is your *machine* itself a member of the domain? Also try going into SQL Server Configuration manager (on your client) and disabling named pipes. Make sure TCP/IP is enabled. Does it work if you use a SQL Server login?
Dave Markle
My machine is not a member of the domain; I disabled named pipes and tcp/ip was already enabled. Then I used the SQL server login and it worked from both the console app and the Windows service!!! Windows authentication does not work using tcp/ip but that's no problem. Thanks very much Dave!
TxDeveloper
+1  A: 

Good Lord! Why all the gibberish and complex responses on this site. Create a User Account
Either local or Domain and set the service to use that account. Then go into your SQL Server and Add you new account to the Database and set permissions. Voila!

Oh yeah, dont plague yourself with SQL Authentication. Integrated Security is much easier to maintain and without a password in your web.config your much safer.

Charles Gardner
Or just use SQL Authentication in your connection string. So much easier.
sliderhouserules

related questions