Solved

SQL Server: connection.Open fails without throwing an exception

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now