how to solve file.copy problem

T

tony

Hi there

when I want to copy a large file(>64K), I got error as follow:

the process cannot access the file, because it is being used by other
process

this is my code as follow
Try
File.Copy("C:\Program Files\Microsoft SQL
Server\MSSQL\Data\test.LDF", "C:\Program Files\Microsoft SQL
Server\MSSQL\Data\TEST2.LDF")
MessageBox.Show("OK")

Catch ex As Exception

MessageBox.Show("Error:" & ex.Message)
End Try

Thanks for any helpful.

Tony
 
R

Raghavendra T V

Hi Tony,

You are trying to copy the .ldf files which are used by MS SQL server.
You need to stop the MS SQL server on your machine which is running.
Only then you will be able to copy it.

I guess you are trying to take a backup of the MS SQL Database through
VB.NET code.
I would suggest you to make use of BACKUP DATABASE SQL command .

Thanks
Raghavendra
 
T

tony

Hi Raghavendra

Thank you for your information, and you are right, It is a MS SQL server
copy, so first I use sp_detech_db to detech the database (like you said,same
stop sql server) , and then make a copy, it is not only backup database, but
is make an absolute copy and save back in same SQL server with other
database name, it is dynamic copy, I only give the database name and let
vb.net make a total new copy with data,view,stored procedure, role ect
inside. I must use program to do it, it is required.

Do you have mre suggestion about that?
Do I have to run at command line to make a copy in vb.net?

Thanks

Tony
 
R

Raghavendra T V

Hi Tony,

To restore the Database what you can do is take a backup of existing DB and
restore it with a different name.
This way you will have a copy of DB.

here is the sampe script to do this.

RESTORE DATABASE TaxReconDB_Prod
FROM DISK = 'D:\Tax\BackUp\TaxReconDB.dmp'
WITH MOVE 'TaxReconDB_Data' TO
'D:\Database\NJROS1D151DEV\MSSQL$NJROS1D151DEV\Data\TaxReconDB_Prod_Data.MDF
'
, MOVE 'TaxReconDB_Log' TO
'D:\Database\NJROS1D151DEV\MSSQL$NJROS1D151DEV\Data\TaxReconDB_Prod_Log.LDF'
, REPLACE

This works fine.Since i have used this in one of my project.

There is no need to run in Command line.(i guess u are thing of using isql
utility and point it to .sql file which contains the Scripts )

Thanks
Raghavendra
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top