how to solve file.copy problem
Messages   Related Types
This message was discovered on microsoft.public.dotnet.faqs.

Post a new message to this list...

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

Reply to this message...
 
    
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
"tony" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
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
"Raghavendra T V" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
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

"tony" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.IO.File
System.Windows.Forms.MessageBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com