J
John
Hi all,
My application updates a sql server 2005 express database prior to copying
it with the result being the "in use by another process" and I cannot copy
it as a result. I've posted the code that updates the database below. Please
could someone let me know how I free up the mdf file properly prior to
copying it.
Otherwise, does someone know how I can free it up programmatically or simply
copy it without receiving the errror?
Regards
John.
SqlCommand cm = null;
SqlConnection cn = null;
bool retcode = true;
try
{
cn = new SqlConnection(connstring);
cn.Open();
cm = new SqlCommand("Delete from tblSys where sys_key = 'exp'");
cm.CommandType = System.Data.CommandType.Text;
cm.Connection = cn;
cm.ExecuteNonQuery();
cm = new SqlCommand("Insert into tblSys (sys_key, sys_val) values('exp', '"
+ newExpDate + "')", cn);
cm.CommandType = System.Data.CommandType.Text;
cm.ExecuteNonQuery();
retcode = true;
}
catch (System.Exception er)
{
retcode = false;
}
finally
{
try
{
if (cm != null)
{
cm.Connection.Close();
cm.Dispose();
}
if (cn != null)
{
if (cn.State == System.Data.ConnectionState.Open)
{
cn.Close();
}
cn.Dispose();
}
}
catch (System.Exception er)
{
retcode = false;
}
}
return retcode;
My application updates a sql server 2005 express database prior to copying
it with the result being the "in use by another process" and I cannot copy
it as a result. I've posted the code that updates the database below. Please
could someone let me know how I free up the mdf file properly prior to
copying it.
Otherwise, does someone know how I can free it up programmatically or simply
copy it without receiving the errror?
Regards
John.
SqlCommand cm = null;
SqlConnection cn = null;
bool retcode = true;
try
{
cn = new SqlConnection(connstring);
cn.Open();
cm = new SqlCommand("Delete from tblSys where sys_key = 'exp'");
cm.CommandType = System.Data.CommandType.Text;
cm.Connection = cn;
cm.ExecuteNonQuery();
cm = new SqlCommand("Insert into tblSys (sys_key, sys_val) values('exp', '"
+ newExpDate + "')", cn);
cm.CommandType = System.Data.CommandType.Text;
cm.ExecuteNonQuery();
retcode = true;
}
catch (System.Exception er)
{
retcode = false;
}
finally
{
try
{
if (cm != null)
{
cm.Connection.Close();
cm.Dispose();
}
if (cn != null)
{
if (cn.State == System.Data.ConnectionState.Open)
{
cn.Close();
}
cn.Dispose();
}
}
catch (System.Exception er)
{
retcode = false;
}
}
return retcode;