我一直在努力将数据库恢复到新数据库,但不断收到错误,说明现有文件无法覆盖。如何指定新的数据库和文件?
更新:我正在使用的命令如下。 TestDB_2.0尚不存在,我希望它能从备份文件中创建。
Restore-SqlDatabase -ServerInstance SERVER-NAME\MSSQL2014 -Database TestDB_2.0 -BackupFile D:\TestWebsite\TestDeployments\testdb.bak -SqlCredential [sa, $pw]
我得到的错误是:
Restore-SqlDatabase : System.Data.SqlClient.SqlError: The file 'C:\Program Files\Microsoft SQL
Server\MSSQL12.MSSQL2014\MSSQL\DATA\TestDB.mdf' cannot be overwritten. It is being used by
database 'TestDB'.
At D:\Projects\Scripting\Scripts\Powershell\Backup-SqlDatabase.ps1:11 char:1
+ Restore-SqlDatabase -ServerInstance WIN-OJR1ILRNQUF\MSSQL2014 -Database TestDB_2 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Restore-SqlDatabase], SmoException
+ FullyQualifiedErrorId : ExecutionFailed,Microsoft.SqlServer.Management.PowerShell.RestoreSql
DatabaseCommand