Checking for table existence

  • Thread starter Thread starter John
  • Start date Start date
Herfried,

I find the IsDate a better sample.

Although I find that the Try should be tried to be avoided is it most
common in by instance sitations as the ISDate. To create all possibilities
in code about that, would cost more then the simple catch for an error (as
it is done behind the scene).

Cor
 
Please, reread what have you written before. How can one "test within a very
good degree of likelihood whether or not the command will
execute properly " without knowing the connection state?


Not to defend a self-admitted troll, but...by having known common
failures.


If a particular condition always causes a failure, and that condition
is the cause of X% of failures, you can avoid making an attempt that is
doomed to failure by first testing the condition.

If X is the vast majority of failures, then your confidence in the
success of an attempt can reasonably be tied to whether or not the
condition exist.

So, empirical data can tell you where to put your effort.

(On the other hand, I think your basic point was that exceptions
shouldn't be used when there is a more straightforward way of returning
the same information is valid).
 
So, empirical data can tell you where to put your effort.

Sure, empirical data helps - but that's it. But you still don't know whether
connection will hold or not as you can't predict future from past.
(On the other hand, I think your basic point was that exceptions
shouldn't be used when there is a more straightforward way of returning
the same information is valid).

Yep, that was my point.
 
So, empirical data can tell you where to put your effort.

And don't forget that doing ping is also a performance issue - you would
need two roundtrips to the server instead of one.
 
Miha Markic said:
And don't forget that doing ping is also a performance issue - you would
need two roundtrips to the server instead of one.

LMAO - you will write any old crap just to try and avoid losing face.
 
SurturZ said:
If a man says something in a forest, is he still wrong? :-)

if a bare-footed girl with clogs on is stood sitting on the grass, can she
get up without moving to go around a straight bend to see an already dead
dog die?
 
I'm going to take mercy on you. I think this is what you are looking for:

private bool TableExists(string connString, string tableName)
{
SqlConnection cn = New SqlConnection(connString);
cn.Open();
DataTable dt = cn.GetSchema("Tables");
foreach (DataRow rw in dt.Rows)
{
if (rw("TABLE_NAME")).ToUpper() == tableName)
return true;
}
return false;
}

RobinS.
 
Back
Top