且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server数据库还原和备份

更新时间:2022-11-25 08:46:31

(1)查看教程



http://www.***.com/watch?v=K2C_ia0KGCc& feature = youtu.be



(2)试用代码

使用我上面提到的免费控制和njoy数据库操作使用更少的代码

(1) View the Tutorial

http://www.***.com/watch?v=K2C_ia0KGCc&feature=youtu.be

(2) Try out the code
use my above mentioned free control and njoy Database operations with less code
dcon.ExecNonQuery("delete from folderPath");
dcon.ExecNonQuery("BACKUP DATABASE Timber_Demo TO  DISK = N'" + txtFName.Text + "'");
MessageBox.Show("Backup Done Successfully");



//恢复操作


//Restore Operation

txtFName.Text = openFileDialog1.FileName;
                   dcc = new DBConClass();
                   // dcc.setSQLConnection(@".\sqlexpress", "master", "sa", "sql");
                   dcc.setSQLConnection(@".", "master", "sa", "sql");
                   string alt = "ALTER DATABASE Timber_Demo SET OFFLINE WITH ROLLBACK IMMEDIATE";
                   dcc.ExecNonQuery(alt);

                   dcc = new DBConClass();
                   // dcc.setSQLConnection(@".\sqlexpress", "master", "sa", "sql");
                   dcc.setSQLConnection(@".", "master", "sa", "sql");
                   string restore = "restore database Timber_Demo from DISK =N'" + txtFName.Text + "'WITH FILE=1,NOUNLOAD,REPLACE,Stats=10";
                   int res = dcc.ExecNonQuery(restore);


                   dcc = new DBConClass();
                   //  dcc.setSQLConnection(@".\sqlexpress", "master", "sa", "sql");
                   dcc.setSQLConnection(@".", "master", "sa", "sql");
                   alt = "ALTER DATABASE Timber_Demo SET ONLINE";
                   dcc.ExecNonQuery(alt);

                   MessageBox.Show("Data Restored successfully");

                   txtFName.Text = "";
                   // dcc.setSQLConnection(@".\sqlexpress", "DBStore", "sa", "sql");
                   dcc.setSQLConnection(@".", "Timber_Demo", "sa", "sql");


请阅读以下链接以恢复sql server数据库。



http://***.com/questions/ 962441 / microsoft-sql-server-restore-a-backup-of-a-database-with-one-command [ ^ ]
please read bellow links for restoring sql server database.

http://***.com/questions/962441/microsoft-sql-server-restore-a-backup-of-a-database-with-one-command[^]