English 中文(简体)
与网络数据库更新和恢复有关的问题
原标题:Issue related to Database Backup and Restore in .Net

I have C#.Net winform application having SQL Server Database in SQLExpress with Windows Authentication. There is a Option related to Backup and restore batabase. In DBbackup i have provided user to select folder and database will be copy to that folder. for restore database i have written following line:

System.IO.File.Copy(filePath, Application.StartupPath + "\dbSTK.mdf",true);

它提出了一种例外,即《德华克法》已经使用。 怎么能够超越已经使用的手法?

最佳回答

mdf文档不是备份,而是实际数据档案。 我们不能简单地复制一个运行的数据库(或超出一个运行的数据库)。 通常,你必须使用<代码>sp_detach_db,以便查阅档案,表明你可以复制/存档和sp_attach_db(或建立附属数据库)。

如果你只是作为背书复制 running,那么奇迹就好了,你就能够照此办理。

虽然以上是打上/打上数据库的正确方法,但我建议实际上进行备份/封顶。 这并不要求将数据库从线上删除,一般是管理备份的更好办法。

http://msdn.microsoft.com/en-us/library/ms179877.aspx“rel=“nofollow”http://msdn.microsoft.com/en-us/library/ms179877.aspx

http://msdn.microsoft.com/en-us/library/ms188031.aspx”rel=“nofollow”http://msdn.microsoft.com/en-us/library/ms188031.aspx

http://msdn.microsoft.com

http://msdn.microsoft.com/en-us/ms186858“rel=“nofollow”http://msdn.microsoft.com/en-us/ms1868

问题回答

Don t backup by just copy the database file. Use the SQL command BACKUP DATABASE. Using this, the server does not need to be stopped and the server can clean up internal stuff.

Do not copy the mdf file. If you want to backup by code, check out this posting Using Smo.Backup to backup SQL Server database to string

If you want to schedule a backup (to your backup folder) create a new maintenance plan using the maintenance plan wizard in sql management studio: http://msdn.microsoft.com/en-us/library/ms189036.aspx





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签