One of my applications doesn't connect to the DB server anymore. This application has been in production for 2 years, without a change and has always worked.
I'm using C# 2010, and MS SQL Server 2008 R2
- I get 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
Inner Exception: "Access is denied"
Using the exact same code, connection string, Database & DB Server, I am able to connect with another application, without any errors.
I am able to connect using SSMS on the server and databases.
The query (if copied to SSMS) runs without a problem.
CODE:
public DataTable QueryRetrieval(string sqlQuery)
{
// SP Command
SqlConnection Conn = new SqlConnection(this.connectionString);
this.Cmd = new SqlCommand(sqlQuery, Conn);
Cmd.CommandType = CommandType.Text; // Type of command
// Declarations (for scope purposes)
SqlDataAdapter Adapter = new SqlDataAdapter(Cmd);
DataTable DtResultSet = new DataTable();
try
{
// Run the query
Conn.Open();
Adapter.Fill(DtResultSet);
Conn.Close();
// Return datatable
return DtResultSet;
}
catch (Exception Ex)
{
// Edit the message, rethrow exception
throw new Exception(
"DataAccessor.QueryDataTable: Failed to run query '" + sqlQuery + "'\n\n"
+ "Error message: \n--------------\n\n" + Ex.Message);
}
finally
{
// Remove the SQL command
Cmd.Dispose();
Cmd = null;
// Remove the SQL data adapter
Adapter.Dispose();
Adapter = null;
}
}
Connection string: "Server=MyServer;Database=MyDB;Trusted_Connection=True;" (I substituted the names.)
The program fails on Conn.Open(); When the codes hits that line, I have to wait 20 or 30 seconds and then the exception is thrown.
No updates have been installed on the server. I have already tried to reboot the server (entire server, not the service).
Is there anyone who has a clue what could cause this to happen?