如何在我的C#应用程序中恢复localdb中的数据库 [英] How to restore the database in localdb in my C# application
本文介绍了如何在我的C#应用程序中恢复localdb中的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Friends,
我在我的应用程序中将我的数据库用作mdf文件,如下连接字符串
Hello Friends,
I used my database as mdf file in my application as following connection string
_sqlCon = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HealthFMRdb.mdf;Integrated Security=True;User Instance=True");
我使用sql server 2008 r2 express现在我想在同一目录下编写恢复我的数据库备份的代码,请帮我怎么做,
提前感谢
我尝试过:
我没有找到满足我需要的代码
I used sql server 2008 r2 express And now I want to writ the code for Restore the backup of my database on this file at the same Directory, please help me how to do that,
thanks in advance
What I have tried:
I didn't find such code that fulfil my need
推荐答案
这不是需要恢复的数据库 - 你正在附加它,这是一个特殊的SQL Express的开发人员模式(在完整版中不可用),它暂时将文件传递给SQL服务器,并旋转一个单独的SQL实例来处理它。当连接关闭时,文件由SQL释放。
因此备份和恢复该文件是一个文件系统功能,与SQL无关。看看你如何备份文件,你应该如何恢复它。
That's not a DB that needs a restore - you are attaching it, which is a special "developer mode" of SQL Express (that isn't available in the full version) which temporarily hands the file to SQL server, and spins up a separate instance of SQL to handle it. When the connection is closed, the file is released by SQL.
So backup and restore of that file is a file system function, nothing to do with SQL. Look at how you backed the file up, and it should be fairly obvious how you restore it.
这篇关于如何在我的C#应用程序中恢复localdb中的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文