473,399 Members | 3,832 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,399 software developers and data experts.

Test connection in Enterprise Library

Jac

Hey,

How can I test if there is an connection-exception when using database
application block from the enterprise service?

I stopped the sqlserver.
I do now the following :

Database db = null;
IDataReader reader = null;
try
{
db = DatabaseFactory.CreateDatabase("Logging");
}
catch (Exception ex)
{
string e = ex.Message;
}

string sqlQuery = "SELECT * FROM log";
try
{
reader = db.ExecuteReader(CommandType.Text, sqlQuery);
}
catch (Exception ex)
{
string e1 = ex.Message;
}

It is only in the second catch that I receive an error.
But just in case of connection problems I want to try it (the
executereader) again after a few seconds.

I receive an SQLException : but how can I see that it is an connection
problem?
And how can I test this when I change my connection to an oracle
database without changing my code in the catch block.

I just need to know there is an connectionproblem independant of which
database (oracle or SQL) I used so I can take actions.

Thanks in advance,
jac

*** Sent via Developersdex http://www.developersdex.com ***
Jan 12 '07 #1
1 2999
Hi,

If you can get at the IDbConnection that the factory creates then just call
the Open method and catch DbException.

To be perfectly honest, though, it shouldn't matter. If after the code
tests the connection it will immediately use it then you shouldn't need to
test it first. It's possible, due to the asynchronous nature of
inter-process communication, that your Open test will succeed but the
factory's try at it will fail immediately afterwards, meaning that you'll
have to catch DbException there anyway and your code still might not be able
to determine the exact cause of the failure.

Your best bet, IMO, is to just use a try..catch(DbException) around the call
to ExecuteReader and forget about determining the exact cause of the
failure. Is there any particular reason why you want to do this?

--
Dave Sexton
http://davesexton.com/blog

"Jac" <ja*@vt4.bewrote in message
news:ec****************@TK2MSFTNGP06.phx.gbl...
>
Hey,

How can I test if there is an connection-exception when using database
application block from the enterprise service?

I stopped the sqlserver.
I do now the following :

Database db = null;
IDataReader reader = null;
try
{
db = DatabaseFactory.CreateDatabase("Logging");
}
catch (Exception ex)
{
string e = ex.Message;
}

string sqlQuery = "SELECT * FROM log";
try
{
reader = db.ExecuteReader(CommandType.Text, sqlQuery);
}
catch (Exception ex)
{
string e1 = ex.Message;
}

It is only in the second catch that I receive an error.
But just in case of connection problems I want to try it (the
executereader) again after a few seconds.

I receive an SQLException : but how can I see that it is an connection
problem?
And how can I test this when I change my connection to an oracle
database without changing my code in the catch block.

I just need to know there is an connectionproblem independant of which
database (oracle or SQL) I used so I can take actions.

Thanks in advance,
jac

*** Sent via Developersdex http://www.developersdex.com ***

Jan 12 '07 #2

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

Similar topics

11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
0
by: Chris Durkin | last post by:
What is the "correct" .NET 2.0 way to do this from within a class library? For example, say I have a connection string in app.config or web.config added using the VS2005 IDE, like so: ...
14
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review,...
7
by: galico | last post by:
Hi All, We are having a very strange problem with the above. We have designed an application in ASP.NET 2.0 that uses the enterprise library data application blocks amongst others. We seem to be...
2
by: SAL | last post by:
Hello, I am working with Framework 1.1 and Microsoft Enterprise Library 2005. I've used the Enterprise Library Configuration utility to create my app.config & dataConfiguration.config files. ...
3
by: rockdale | last post by:
I am using Microsoft.Practices.Enterprise.Library When I use IDataReader I saw this line "It is the responsibility of the caller to close the connection and reader when finished." I was...
4
by: -pb- | last post by:
I am using .NET 2.0 along with Data Access Application Block of Enterprise Library 2.0 in one of my wrapper class and what I observered is once the connection is left open after execution of...
1
by: Victor | last post by:
Hi guys I have a question here. I am currently using Enterprise Library Jan 2006 version. I found out where i execute the Database.executeDataSet() the Enterprise Library will not close the...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL 2005. To use connection pooling and avoid the error "There is already an open DataReader associated with this Connection which must be closed first." , I understand...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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.