Solved

SQL Server: connection.Open fails without throwing an exception

Posted on 2008-10-14
3
470 Views
Last Modified: 2013-12-17
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
Comment
Question by:kenfhenderson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 22717408
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
 

Author Closing Comment

by:kenfhenderson
ID: 31506155
That's exactly what it was!
Thanks for the super quick answer.
Ken
0
 
LVL 3

Expert Comment

by:trunghieubkit
ID: 22717491
Replace yours by
string connectProject = "";
you'll see exception
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question