PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Pb with DataAdapter.Fill
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Pb with DataAdapter.Fill
![]() |
Pb with DataAdapter.Fill |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Hi,
I believe if database does not exist, then you suppose to get an exception when you try to open database. You do not need to call Fill of the DataAdapter to do this. Anyway, if you need to call Fill for some reason, then it is better to call Dispose method of the DataAdapter after you got an exception, set variable to null an then continue -- Val Mazur Microsoft MVP http://xport.mvps.org "bp" wrote: > 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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

