使用TSQL备份和还原SQL数据库 [英] BackUp and Restore SQL Database Using TSQL

查看:144
本文介绍了使用TSQL备份和还原SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我叫Vikash Gohil.

我必须根据以下需求创建一个应用程序.

在2个SQL2000实例下,有2个具有相同名称和结构的数据库.

该应用程序将连接到两个数据库.

然后,它将使用TSQL备份两个数据库.

然后它将一些数据从第二数据库复制到第一数据库.

然后再次备份第一个数据库.

在第二个数据库中还原上一步中获得的备份.

再次使用步骤1中的备份还原第一个数据库.

现在,我已经设法使用TSQL在数据库之间进行备份和复制数据

恢复这些数据库时会出现问题.

它显示错误:无法获得对数据库的独占访问权限.恢复数据库失败.

在还原之前,我还已将数据库设置为单用户模式,但是存在相同的问题.

使用独立的sql连接对象执行单独数据库上的每个进程.

我使用以下代码还原数据库.

昏暗的SqlC作为新的SqlCommand
SqlC.Connection = MyConn
SqlC.CommandText =具有立即回滚的ALTER DATABASE [DBName] SET SINGLE_USER"
SqlC.ExecuteNonQuery
SqlC.CommandText =从磁盘还原数据库[DBName] =" [文件路径]"
SqlC.ExecuteNonQuery
SqlC.CommandText ="ALTER DATABASE [DBName] SET MULTI_USER"
SqlC.ExecuteNonQuery

在这种情况下有人可以帮我吗?

任何帮助将不胜感激.

在此先感谢.

Hello, this is Vikash Gohil.

I have to Create an Application based on the following needs.

There are 2 databases with Same name and Structure under 2 SQL2000 instances.

The Application will connect to both databases.

It will then take backup of both databases using TSQL.

Then It will Copy some data from 2nd database to 1st database.

Then Take backup of 1st database again.

Restore the backup ,taken in previous step, in the 2nd database.

Again restore the 1st database with the backup taken in step 1.

Now I have managed to Takes backups and Copy data between databases using TSQL

The problem occurs while restoring these databases.

It shows error : Exclusive Access rights to the database cannot be obtained. restore database fails.

I have also set database to single user mode before restoring but the same problem exists.

each process on separate database is performed using its own sql connection object.

I use the below code for restoring the databases.

Dim SqlC as New SqlCommand
SqlC.Connection = MyConn
SqlC.CommandText = "ALTER DATABASE [DBName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE"
SqlC.ExecuteNonQuery
SqlC.CommandText = "RESTORE DATABASE [DBName] FROM DISK = ''[filepath]''"
SqlC.ExecuteNonQuery
SqlC.CommandText = "ALTER DATABASE [DBName] SET MULTI_USER"
SqlC.ExecuteNonQuery

Can Somebody Help me in this case.

Any Help Would be greatly appreciated.

Thanks in Advance.

Awaiting a reply soon.

推荐答案

我将看看此

这篇关于使用TSQL备份和还原SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆