473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Sqlconn.open() doesn't work after starting sql server. Weird problem.

Sam
I have an application that sits in the traybar that calls a msde sp3a
database to verify that the connection to the sql server instance exists.
If the sql server is up obviously the application runs perfectly. If the
database is brought down on purpose or by a machine shutting down and the
VerifyDBConnection() function is called it fails. So far so good. Now if
the VerifyDBConnection() is called repeatedly while the database is down it
no longer connects to the database even if the database instance is
restarted
again. The exception happens on sqlConn.Open();. What makes me feel horrible
is that if the application is closed and opened again the database
connectivity runs perfectly again. This rules out any ip
address/password/network failure issues.

Why does it require that the application restart before connecting properly
again. It should connect correctly to the database as soon as the
verifydbconnection() function is called on the instance that is restarted.
I performed the test again and again maybe thinking that the datareader is
pooling connections. So I began using the sqlDataReader =
sqlCmd.ExecuteReader(System.Data.CommandBehavior.C loseConnection); . It
still does the same thing.

private bool VerifyDBConnection()

{

Console.WriteLine(DateTime.Now.ToString() + ":" + "VerifyDBConnection");

bool bResult = false;

SqlConnection sqlConn;

SqlDataReader sqlDataReader;

SqlCommand sqlCmd;
sqlConn = new System.Data.SqlClient.SqlConnection();

sqlConn.ConnectionString = m_strConnection;

sqlCmd = new SqlCommand("SELECT getdate() as dateverify", sqlConn);
try

{

sqlConn.Open();

}

catch (System.Exception ex)

{

Console.WriteLine(DateTime.Now.ToString() + ":" + "Exception
VerifyDBConnection SqlConnection open:" + ex.Message);

this.Cursor = Cursors.Default;

bResult = false;

return bResult;

}

finally

{

}

try

{

sqlDataReader =
sqlCmd.ExecuteReader(System.Data.CommandBehavior.C loseConnection);
if(sqlDataReader.Read())

{

bResult = true;

}

sqlDataReader.Close();
}

catch (System.Exception ex)

{

Console.WriteLine(DateTime.Now.ToString() + ":" + "Exception
VerifyDBConnection DataReaderException");

this.Cursor = Cursors.Default;

}

finally

{
sqlConn.Close();

}

this.Cursor = Cursors.Default;

return bResult;

}


Nov 17 '05 #1
1 2454
Sam - this is a known behavior due to connection pooling. If the app is
connected to the db and the db goes down, then it goes back up the app will
need to cycle through everything in the pool (which is a fancy way of saying
you'll get a bunch of exceptions even though the db is available). In the
2.0 Framework, this will only happen once with the SqlClient provider and w/
the Oracle provider, it won't happen at all.
"Sam" <sa*@info.com> wrote in message
news:11*************@corp.supernews.com...
I have an application that sits in the traybar that calls a msde sp3a
database to verify that the connection to the sql server instance exists.
If the sql server is up obviously the application runs perfectly. If the
database is brought down on purpose or by a machine shutting down and the
VerifyDBConnection() function is called it fails. So far so good. Now if
the VerifyDBConnection() is called repeatedly while the database is down
it
no longer connects to the database even if the database instance is
restarted
again. The exception happens on sqlConn.Open();. What makes me feel
horrible
is that if the application is closed and opened again the database
connectivity runs perfectly again. This rules out any ip
address/password/network failure issues.

Why does it require that the application restart before connecting
properly
again. It should connect correctly to the database as soon as the
verifydbconnection() function is called on the instance that is restarted.
I performed the test again and again maybe thinking that the datareader is
pooling connections. So I began using the sqlDataReader =
sqlCmd.ExecuteReader(System.Data.CommandBehavior.C loseConnection); . It
still does the same thing.

private bool VerifyDBConnection()

{

Console.WriteLine(DateTime.Now.ToString() + ":" + "VerifyDBConnection");

bool bResult = false;

SqlConnection sqlConn;

SqlDataReader sqlDataReader;

SqlCommand sqlCmd;
sqlConn = new System.Data.SqlClient.SqlConnection();

sqlConn.ConnectionString = m_strConnection;

sqlCmd = new SqlCommand("SELECT getdate() as dateverify", sqlConn);
try

{

sqlConn.Open();

}

catch (System.Exception ex)

{

Console.WriteLine(DateTime.Now.ToString() + ":" + "Exception
VerifyDBConnection SqlConnection open:" + ex.Message);

this.Cursor = Cursors.Default;

bResult = false;

return bResult;

}

finally

{

}

try

{

sqlDataReader =
sqlCmd.ExecuteReader(System.Data.CommandBehavior.C loseConnection);
if(sqlDataReader.Read())

{

bResult = true;

}

sqlDataReader.Close();
}

catch (System.Exception ex)

{

Console.WriteLine(DateTime.Now.ToString() + ":" + "Exception
VerifyDBConnection DataReaderException");

this.Cursor = Cursors.Default;

}

finally

{
sqlConn.Close();

}

this.Cursor = Cursors.Default;

return bResult;

}

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Paul | last post by:
I link to a web site from an Excel spreadsheet. The page i link to is getCookie.asp which sets a cookie then returns back some html which opens a new window, to the same site but a different page...
4
by: Phillip Parr | last post by:
Hello, I have a nice system where someone clicks on a picture to show the full version. This pops up in a window.open box. It works great, the only problem is that if the user clicks a second...
1
by: Kevin Vogt | last post by:
When initially loaded, my web application (below) takes ~120000 milliseconds to open its connection. But repeated executions take 0 milliseconds each. But when I wait for approx. 5 minutes and try...
1
by: Richard \(MrBonus\) | last post by:
the code is taken from my asp.net page. (written in C#) Hi, im trying to make my page postback before the it unloads, i've tried a lot of stuff, and finally I made something that worked, the...
55
by: Steve Jorgensen | last post by:
In a recent thread, RKC (correctly, I believe), took issue with my use of multiple parameters in a Property Let procedure to pass dimensional arguments on the basis that, although it works, it's...
5
by: Mike Turco | last post by:
This is the second day with the second database from a second person on a second computer that I have had this problem. When somebody emails a database to me and I try to open it, I first get a...
6
by: B B | last post by:
Okay, here is what's happening: I have a reasonably fast laptop (1.4 GHz Mobile M, so comparable to 2.5GHz P4) doing .net development. Running Windows XP pro, SP2 IIS is installed and running...
11
by: Dave | last post by:
For some reason, the below lines only work on select machines. All machines are running IE6. IE SP's and OS's vary. When it doesn't work, default.aspx (the page that this code is in) opens and...
2
by: sqlgirl | last post by:
Hi, We have 2 servers. Server1 is a 2000 box, with SP3 (yes I know it is not up to date). Server2 is a 2005 box, SP2. I set up Server1 (2000) to have a linked server to Server2 (2005). The...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.