[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SQL Server: connection.Open fails without throwing an exception

Posted on 2008-10-14
3
Medium Priority
?
477 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 2000 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 Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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