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 ***