Hello!
If I create and open the connection, and then use
this connection in a command, that used in a dataadapter,
after adapter.Dispose() the connection for
command set to null(call command.Dispose()).
But i don't want dispose my command object. I
plan to use it later, and want dispose with myself.
-------------------------------------------
private
static void testFb()
{
FbConnectionStringBuilder cs = new FbConnectionStringBuilder();
cs.DataSource = "localhost";
cs.Database = @"D:\test.fdb";
cs.UserID = "USER";
cs.Password = "PASSW";
cs.Dialect = 3;
cs.ServerType = FbServerType.Embedded;
FbConnection con = new FbConnection(cs.ConnectionString);
FbCommand cmd = con.CreateCommand();
con.Open();
cmd.CommandText = "select * from \"users\"";
DataTable
result = new DataTable();
FbDataAdapter adapter = new
FbDataAdapter(cmd);
adapter.Fill(result);
adapter.Dispose();
cmd.CommandText = "select count(*) from \"users\"";
int r =
Convert.ToInt32(cmd.ExecuteScalar()); // <-catch exeption "Connection
must vzlid and open"
}
--------------------
private
static void testSql()
{
SqlConnectionStringBuilder cs = new SqlConnectionStringBuilder();
cs.DataSource = ".";
cs.InitialCatalog = @"test";
cs.IntegratedSecurity = true;
cs.Pooling = false;
SqlConnection con = new SqlConnection(cs.ConnectionString);
SqlCommand cmd = con.CreateCommand();
con.Open();
cmd.CommandText = "select * from users";
DataTable
result = new DataTable();
SqlDataAdapter adapter = new
SqlDataAdapter(cmd);
adapter.Fill(result);
adapter.Dispose();
cmd.CommandText = "select count(*) from users";
int r =
Convert.ToInt32(cmd.ExecuteScalar()); // <- all
right
}
-----------------------
may be write so (in
FbDataAdapter.Dispose())
----
// Release any
managed resources
if (disposing)
{
if (this.SelectCommand != null)
{
this.SelectCommand = null; //this.SelectCommand.Dispose(); }
if (this.InsertCommand != null)
{
this.InsertCommand = null; //this.InsertCommand.Dispose();
}
if (this.UpdateCommand != null)
{
this.UpdateCommand = null; //this.UpdateCommand.Dispose();
}
}
----
with best
regards
|
- [Firebird-net-provider] About DataAdapter.Dispose(... sunika
- Re: [Firebird-net-provider] About DataAdapter... Carlos Guzmán Álvarez