Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

SQL Server: connection.Open fails without throwing an exception

Greetings,
In the code snippet below - I place a SQL Server connection.Open in a try block incase it throws an exception.
If I mung the server name in the connection string, and single step it - the Open simply hangs, without throwing an exception.

What am I missing?

Thanks much - Ken
string connectProject = Properties.Settings.Default.PS2007ReportingConnection;
            string projectSQL = "SELECT ProjectUID, ProjectName, BaaN_ProjectID FROM MSP_EpmProject_UserView";
            OutputUtilsLogs ulog = new OutputUtilsLogs();
            DataTable dt = new DataTable();
 
            using (SqlConnection connection = new SqlConnection(connectProject))
            {
                SqlCommand command = new SqlCommand(projectSQL, connection);
 
                try
                {
                    connection.Open();
                }
                catch (Exception ex)
                {
                    ulog.writeNTConsoleAndEventLog(ex, "Actuals", "--SQL connection Open from getProjectView failed.");
                    throw (ex);
                }

Open in new window

0
kenfhenderson
Asked:
kenfhenderson
1 Solution
 
BrandonGalderisiCommented:
A failed connection may not be exception.  Or, the connection timeout is just set so high (like 0 for indefinite) that it appears to be hung when it is just trying to connect.  You may want to try dropping the connection timeout lower.  I think if a db doesn't respond in 5 second it's been too long.
0
 
kenfhendersonAuthor Commented:
That's exactly what it was!
Thanks for the super quick answer.
Ken
0
 
trunghieubkitCommented:
Replace yours by
string connectProject = "";
you'll see exception
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now