SQL Server中禁用了数据库报告选项

时间:2017-02-21 19:28:38

标签: sql-server powershell ssms

我通过运行PowerShell脚本从.bak文件恢复了数据库。今天,当我尝试使用" Reports"检查数据库时,我注意到它已被禁用。请参见屏幕截图:

enter image description here

我不太确定用于恢复数据库的脚本是否有任何问题,但这里是:

$restoredDbName = "dbx"

[string] $dbCommand = "RESTORE DATABASE [$($restoredDbName)] " +
                    "FROM    DISK = N'$($bakFilePath)' " +
                    "WITH    FILE = 1," + 
                    "MOVE N'$($fileLogicalName)' TO     N'$($restorePathD)\$($restoredDbName).mdf'," +
                    "MOVE N'$($fileLogicalName)_Log' TO N'$($restorePathD)\$($restoredDbName)_Log.ldf',"

if($bakFilename.Contains("xyz")) {
    $dbCommand += "MOVE N'abc' TO N'$($restorePathD)\$($restoredDbName).ndf',"
}

$dbCommand += "NOUNLOAD,  REPLACE,  STATS = 1"

2 个答案:

答案 0 :(得分:0)

很少有尝试:

它可能是未正确安装的IIS角色。 常见的HTTP功能(全选) 应用程序开发(选择ASP .NET) 安全性(Windows身份验证)

可能是SSMS没有作为管理员“以管理员身份运行”运行,即右键单击SSMS图标或菜单选项并选择“以管理员身份运行”。试一试。

我确定它不是PowerShell脚本。 另外,我在您的PowerShell脚本中看到SQL的一些问题。这是我恢复数据库的goto脚本。

$DBName="RestoreDB"
$fileLogicalName_DATA="XYZ"
$fileLogicalName_LOG="XYZ_LOG"
$backupFilePath="D:\RestoreDB.bak"
$Datafilepath="D:\DataStore" #Do not add the trailing \
$Logfilepath="D:\LogStore" #Do not add the trailing \
$dbCommand = "use [master];RESTORE DATABASE [$DBName] " + "FROM DISK = N'$backupFilePath'" + "WITH FILE = 1, NOUNLOAD, STATS = 10, " + "move '$fileLogicalName_DATA' to '$Datafilepath" + "\" + "$DBName" + "_data.mdf', " + "move '$fileLogicalName_LOG' to '$Logfilepath" + "\" + "$DBName" + "_log.ldf';" + "alter database [$DBName] modify file (name=N'$fileLogicalName_DATA', newname=N'$DBName" + "_data');" + "alter database [$DBName] modify file (name=N'$fileLogicalName_LOG', newname=N'$DBName" + "_log');" + "alter database [$DBName] set read_committed_snapshot on with rollback immediate;" + "alter database [$DBName] set COMPATIBILITY_LEVEL = 100;"
sqlcmd -S $DBServerName -E -Q $dbCommand -r0

答案 1 :(得分:0)

这是因为您的SSMS的版本比与运行中的sql Server实例版本兼容所需的版本更早。

尝试升级您的ssms。这应该可以解决问题。