Solved

SQL Server: connection.Open fails without throwing an exception

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

733 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