G
Guest
Hi
I'm trying to make a component to manage database access. One task of this
component is to create a database if it does not exist. To minimize queries's
count, I want to do database creation when DataAdapter.Fill fails (and if the
database doesn't exist). So I wrote the following code :
try
{
dataAdapter.Fill(ds);
}
catch
{
// Use a connection on master database to create a database
connectionMaster.Open();
commandMaster.ExecuteNonQuery(); // Create database query
connectionMaster.Close();
dataAdapter.Fill(ds);
}
But it fails on the second DataAdapter.Fill : "Can't open connection"
When I wrote the following code, it works :
connectionMaster.Open();
commandMaster.ExecuteNonQuery();
connectionMaster.Close();
dataAdapter.Fill(ds);
It seems that some resources have been blocked by the first
DataAdapter.Fill. How can I make my first code work ?
Thanks for responses.
bp
I'm trying to make a component to manage database access. One task of this
component is to create a database if it does not exist. To minimize queries's
count, I want to do database creation when DataAdapter.Fill fails (and if the
database doesn't exist). So I wrote the following code :
try
{
dataAdapter.Fill(ds);
}
catch
{
// Use a connection on master database to create a database
connectionMaster.Open();
commandMaster.ExecuteNonQuery(); // Create database query
connectionMaster.Close();
dataAdapter.Fill(ds);
}
But it fails on the second DataAdapter.Fill : "Can't open connection"
When I wrote the following code, it works :
connectionMaster.Open();
commandMaster.ExecuteNonQuery();
connectionMaster.Close();
dataAdapter.Fill(ds);
It seems that some resources have been blocked by the first
DataAdapter.Fill. How can I make my first code work ?
Thanks for responses.
bp