gpt4 book ai didi

sql-server - 用户没有 RESTORE 数据库的权限

转载 作者:行者123 更新时间:2023-12-02 22:23:58 26 4
gpt4 key购买 nike

我正在使用下面的代码来备份本地 SqlExpress 数据库上的数据库。

  procedure RestoreScoreDb(DBName,OldName,BackName : String);
var
cmd : WideString;
SqlBackupDir : String;
SqlDataDir : String;
begin
Try
ConnectionMaster.Connected := False;
ConnectionMaster.Close;
ConnectionMaster.ConnectionString := 'Provider=SQLNCLI11.1;Integrated Security="";Persist Security Info=False;User ID=SA;Password=Tccc1234;OLE DB Services=-2;Initial Catalog="master";Data Source=\SQLEXPRESS;Initial File Name="";Packet Size=4096;Auto Translate=True;Server SPN=""';
SqlBackupDir := ReadIniStr(IniCfg,'Dir','SqlBackup');
SqlDataDir := ReadIniStr(IniCfg,'Dir','SqlData');
cmd := 'RESTORE DATABASE '+DBName;
cmd := Cmd + ' FROM DISK = N'''+SqlBackupDir+'\'+BackName+'''';
cmd := Cmd + ' WITH FILE = 1';
cmd := cmd + ' , MOVE N'''+OldName+''' TO N'''+SqlDataDir+'\'+DBName+'.mdf''';
cmd := cmd + ' , MOVE N'''+OldName+'_log'' TO N'''+SqlDataDir+'\'+DBName+'.ldf''';
cmd := cmd + ' , NOUNLOAD, REPLACE, STATS = 10';
CmdRestore.CommandText := cmd;
CmdRestore.Connection := ConnectionMaster;
CmdRestore.Execute;
except
on E: Exception do
writeln(LogFile,'RestoreScoreDb = '+E.Message);
end;
end;

恢复命令是

cmd ='RESTORE DATABASE score_import FROM DISK = 
N''C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Backup\score_import.bak''
WITH FILE = 1 , MOVE N''score_import'' TO
N''C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\score_import.mdf'' ,
MOVE N''score_import_log'' TO N''C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\score_import.ldf'' ,
NOUNLOAD, REPLACE, STATS = 10'

当我复制并粘贴到管理工作室时,它可以毫无问题地恢复表。但是当我运行此代码时,出现错误:

User does not have permission to RESTORE database "score_import"

SA 拥有完全权限。知道我缺少什么吗? Delphi XE6、Windows 10 Sql 2012。

最佳答案

感谢内河码头的支持。他们可以重现我的问题并通过从连接字符串中删除 Integrated Security="" 来解决它。如果您对原因感兴趣,请在 Google 中搜索“ADO Integrated Security”。

关于sql-server - 用户没有 RESTORE 数据库的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44372615/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com