Solved

SQL Server: connection.Open fails without throwing an exception

Posted on 2008-10-14
3
462 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
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

943 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now