473,396 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Locking a database file prior to copying it

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;
May 21 '06 #1
3 1492

"John" <a@b.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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?


Did you attach the db file in your connection string? If so did you turn
off connection pooling in the connection string?

You can always manually detach the database by running sp_detach_db.

David
May 21 '06 #2
Hi David,

Thanks a lot for the response - I've tried neither suggestions. I'll give it
a try in a while and get back to you.

Regards
John.
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:OO**************@TK2MSFTNGP03.phx.gbl...

"John" <a@b.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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?


Did you attach the db file in your connection string? If so did you turn
off connection pooling in the connection string?

You can always manually detach the database by running sp_detach_db.

David

May 21 '06 #3
Hi David,

The pooling didn't work for me but the explicit call to detach the db did -
I did, however, have to put in a thread.wait for 10 seconds (actually 5 did
the trick but I want to be sure) to allow a little time for detachment.

Thanks a lot.

Regards
John.

"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:OO**************@TK2MSFTNGP03.phx.gbl...

"John" <a@b.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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?


Did you attach the db file in your connection string? If so did you turn
off connection pooling in the connection string?

You can always manually detach the database by running sp_detach_db.

David

May 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
4
by: Sam | last post by:
Hello everyone, I have around 20 reports in an ASP web-application which connects to a SQL Server 2000 dB, executes stored procedures based on input parameters and returns the data in a nice...
375
by: rkusenet | last post by:
This article is very bleak about future of DB2. How credible is the author. http://www.eweek.com/article2/0,1895,1839681,00.asp
51
by: John Baker | last post by:
Hi: Some time ago I developed a program in Access, and separated the database and the program itself (using the normal access tools).We have the db on our server and the programin the desktop...
2
by: Peter | last post by:
(I've tried this Q in the ms forums without response. See how it goes here.) Using A2003 but I guess this is not version-specific... If I want to implement row/record level locking on a split...
19
by: Andy B | last post by:
Hello, Sorry for this newbish question. Briefly, my problem: ------------------ I expect the database I'm working on to reach something in the order of 12-16 Gigabytes, and I am interested...
12
by: Peteroid | last post by:
I was creating my application just fine for the last 3 weeks or so. Then, starting this morning, IntelliSense seems to be having problems. It goes into a locked 'Updating IntelliSense..." mode....
4
by: Jerry Spence1 | last post by:
I am creating a database as so: Dim cat As New ADOX.Catalog() Dim CurDB as String Dim sCreateString As String CurDB = "MyDatabase.mdb" sCreateString =...
0
by: tbeers | last post by:
Good afternoon. I am ready to deploy a database using access 2007. Been pretty happy with the development process. However, the application will be used over a terminal server network...windows...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.