Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello
I work with entity framework. my db files in a directory.
I want get backup the database files. What software do move these two files?
This program is run when files are locked.
Is there any way other than copying files?
Posted
Comments
Keith Barrow 22-Aug-11 3:26am    
Is there any reason you can't just backup the database normally, without involving the entity framework?

If you are using MDBs then they will always be locked when in use. One way to do it would be to write a whackload of stored procs, wrap them with a 'backup' proc and call that from the client.

Consider using SQL 2008 Express, and host the DB there. That way you would be able to create backup maintenance plans, have other servers pull the data, etc. Lots of options. You can even use SQL Server Management Studio to do the backups by hand.

Cheers.
 
Share this answer
 
v2
Comments
esmailian 23-Aug-11 5:36am    
my file extension is .mdf .but my db file not attach in SQL server . my connect to file and I need a trick to copy this file when my program run .
TheyCallMeMrJames 23-Aug-11 11:00am    
I'm sorry, esmailian, you're trying to do something that is designed not to happen here. Can you not figure a different approach? If the file is locked, it's locked. The OS won't let you carry the operation out. EF is not going to enable you to do this. You will likely need to write some really low level unmanaged code to do this.

Edit: read new answer below for one possible option. /eatingCrow
I'm going to backtrack a bit...as it turns out you can use the shadow copy approach, but it may not fit your needs as you've described above. Certainly, it cannot be done with EF.

http://www.codeproject.com/KB/dotnet/makeshadowcopy.aspx?display=Print
Cheers.
 
Share this answer
 
v2
Comments
esmailian 23-Aug-11 15:22pm    
Thank TheyCallMeMrJames but I cant work with vb . I work c#
 
Share this answer
 
v2
Database backup is a part of Maintenance not part of programming so go to Maintenance Plan feature of SQL server Management Studio.

How to: Create a Maintenance Plan, use :http://msdn.microsoft.com/en-us/library/ms189953(v=sql.105).aspx[^]

If you are using Express Editon (thus no SQL Server Agent is available for Maintenance Plan) see script given by ; http://ola.hallengren.com/[^] , Here free script is given.
 
Share this answer
 
v3
Comments
CHill60 25-Jan-14 12:24pm    
Good links but I really hope the OP hasn't waited over 2 years to take a backup

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900