I have a console application that runs twice a day from a job in Task Scheduler.
The application connects to three different databases and does some housework (reconciling different tables).
Upon completion the job sends me an email informing me of either SUCCESS or FAILURE. Until a couple of days ago the application ran successfully. However, a couple of days ago I began receiving FAILURE messages.
The message is (condensed for readability):
System.Data.SqlClient.SqlException (0x80131904): 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) ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found
at MyProg.Program.Main(String[] args) in C:\BuildAgent6\work\b8eceaf26d023592\MyProg\MyProg\Program.cs:line 29
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:53,State:0,Class:20
However, if I run the application manually (locating the exe in the file system and double-clicking) everything runs correctly to completion.
I have determined that the connection strings for database connection are correct.
I have determined that the account under which the job runs has the correct permissions (if it did not, then the application wouldn't even get to the stage where it was attempting the database connection). In fact, the line in Program.cs where the application barfs is the second database connection; the first connection has already succeeded. There is nothing I can see about the Login or User on this particular database that would cause the error (and, if there were, why would it succeed when invoked manually?)
So I guess the bottom line is: why would a program called from a Task Scheduler fail to connect to a database using connection strings stored in App.Config, but succeed when called manually?
User contributions licensed under CC BY-SA 3.0