C
Ciaran
Hi there,
I recently came across a SQL CE BUG, which is documented by Microsoft
http://support.microsoft.com/default.aspx?scid=kb;EN-US;824462
The Resolution of this requires that I call the Dispose method for the
SqlCeCommand instances used with the SqlCeDataAdapter. If I use this
resolution my code looks like the following:
SqlCeCommand cmd = null;
protected SqlCeCommand GetMyCommand()
{
if (cmd == null)
{
cmd = new SqlCeCommand();
cmd.CommandText = "SELECT * FROM Table";
cmd.Connection = mySQLConnection;
try
{
cmd.Connection.Open();
cmd.Prepare();
}
Catch {...}
finally
{
cmd.Connection.Close();
}
}
return cmd;
}
mySqlAdapter.SelectCommand = GetMyCommand();
try
{
mySqlAdapter.Fill(...)
}
catch {...}
finally
{
if (sqlAdapter.SelectCommand != null)
sqlAdapter.SelectCommand.Dispose();
}
Here's my question.....
If I need to Dispose of the cmd after I use it, then if I use it again
I need to re-initialise it, which means I need to create the cmd each
time as follows:
protected SqlCeCommand GetMyCommand()
{
SqlCeCommand cmd = new SqlCeCommand()
cmd = new SqlCeCommand();
cmd.CommandText = "SELECT * FROM Table";
cmd.Connection = mySQLConnection;
......
}
Does this mean that there is no point in calling Prepare(), as I
thought
the point of Prepare() was you call it once to compile the cmd once.
Any
insight is much appreciated.
I recently came across a SQL CE BUG, which is documented by Microsoft
http://support.microsoft.com/default.aspx?scid=kb;EN-US;824462
The Resolution of this requires that I call the Dispose method for the
SqlCeCommand instances used with the SqlCeDataAdapter. If I use this
resolution my code looks like the following:
SqlCeCommand cmd = null;
protected SqlCeCommand GetMyCommand()
{
if (cmd == null)
{
cmd = new SqlCeCommand();
cmd.CommandText = "SELECT * FROM Table";
cmd.Connection = mySQLConnection;
try
{
cmd.Connection.Open();
cmd.Prepare();
}
Catch {...}
finally
{
cmd.Connection.Close();
}
}
return cmd;
}
mySqlAdapter.SelectCommand = GetMyCommand();
try
{
mySqlAdapter.Fill(...)
}
catch {...}
finally
{
if (sqlAdapter.SelectCommand != null)
sqlAdapter.SelectCommand.Dispose();
}
Here's my question.....
If I need to Dispose of the cmd after I use it, then if I use it again
I need to re-initialise it, which means I need to create the cmd each
time as follows:
protected SqlCeCommand GetMyCommand()
{
SqlCeCommand cmd = new SqlCeCommand()
cmd = new SqlCeCommand();
cmd.CommandText = "SELECT * FROM Table";
cmd.Connection = mySQLConnection;
......
}
Does this mean that there is no point in calling Prepare(), as I
thought
the point of Prepare() was you call it once to compile the cmd once.
Any
insight is much appreciated.