1

I have a windows service running and when it tries to connect the database, I've got an exception : "The underlying provider failed on open". The same service works fine on Windows Server 2008 R2 but it doesn't work on my computer with Windows7.

I tried with integrated security and without integrated security, it is the same issue.

I tried to connect the database on windows server 2008 R2 by changing connection string but it doesn't work.

The service use a visual studio installer(.vdproj) but I have the same error using installshield LE Spring 2012.

The database is used by an .NET MVC3 project and the connection works fine.

How can I fix this connection error ?

Thank you for your help.

Jordan Gueguen
  • 128
  • 3
  • 11
  • 1
    Is the Windows Service running under LOCAL SYSTEM account ? You may want to change it to NETWORK SERVICE account in order for it to be allowed to go through the network.. Also check MSDTC service security settings. – Madushan Nov 28 '12 at 10:59
  • Windows firewall being bad-ass ? (Your Server 2008 R2 instance may have the firewall down, assuming it's on a DMZ) – Madushan Nov 28 '12 at 11:01
  • @Madushan Yes, it is running under LOCAL SYSTEM account. The windows service and the database are on the same machine, do I really need to change it for Network Service ? – Jordan Gueguen Nov 28 '12 at 15:30
  • @Madushan I tried the service with firewall down but I have the same exception :/ – Jordan Gueguen Nov 28 '12 at 15:31
  • Hmm... Can you post the code which is causing the issue, and the code of the MVC application that works on your Win7 machine ? Do you use EF to access the database ? – Madushan Nov 29 '12 at 05:05
  • 1
    May be your Windows service can't connect to MSDTC. Can you check whether it's running and its security settings ? Also Read http://stackoverflow.com/questions/2475008/the-underlying-provider-failed-on-open – Madushan Nov 29 '12 at 05:08
  • @Madushan I use EF / DbContext to access the database, that's right. I don't know which instruction causing the exception because when I run it with visual studio debugger, I don't have this exception, it works fine... Only the service when it is installed on my computer and running, it can't connect database. – Jordan Gueguen Nov 29 '12 at 09:43
  • @Madushan I have more information about the exception. It is "login failed for user 'nt authority\system' " – Jordan Gueguen Nov 29 '12 at 09:45

1 Answers1

3

The windows service didn't have enough rights to connect the database, so I add the role "sysadmin" to the NT AUTHORITY\System user and the exception is gone !

Thank you Madushan for your help :)

Jordan Gueguen
  • 128
  • 3
  • 11
  • Adding sa to the system user is a little frowned upon, because you're allowing pretty much every software running on as a service, to access your database with no restrictions. I recommend you create a separate account for your service. – Madushan Nov 30 '12 at 02:19
  • @Madushan it's just for local development, I don't use integrated security on production server – Jordan Gueguen Nov 30 '12 at 09:32