troubleshooting Question

C# Console Application cannot see SQL Server when running as a Scheduled Task?

Avatar of lee_K
lee_K asked on
.NET ProgrammingMicrosoft SQL Server 2005
12 Comments1 Solution1397 ViewsLast Modified:
Hi all, I have developed a simple C# Console application. In the connection string I am using a named SQL Server Login, so not Windows Auth and the application works fine and I can connect to the database.

I set this up to run as a scheduled task, and it runs when the Task is set up to use my Username/Password with no problems.

I created a new user specifically to run this (good practise to not have it running as me obviously), added them to the Administrators group of the machine, and configured the Task to use this new user.

When the task runs using the new user, the code fails with the following error on each of the attempts to access the database.

'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)'

Which is your standard SQL Server Access Denied error. I also tried configuring the task to run as the NT AUTHORITY\SYSTEM user and get the same problem. I used SQL Profiler to ensure the user coming through was the one named in the connection string and that is fine.

To double check it is related to the user, I logged into the machine as the new user and tried running from the command line and I get the same error.

Any ideas? Thanks in advance.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros