I want to restore a SQL Server .bak
backup file in InnoSetup.
Here is the code I use:
try
ExtractTemporaryFile ('mydb.bak');
ADOConnection := CreateOleObject('ADODB.Connection');
ADOConnection.ConnectionString :=
'Provider=SQLOLEDB;' + // provider
'Data Source=DESKTOP-UE6ST1P\RMPRO;' + // server name
'Initial Catalog=master ;' + // default database
'User Id=sa;' + // user name
'Password=mypass;'; // password
ADOConnection.Open;
try
ADOCommand := CreateOleObject('ADODB.Command');
ADOCommand.ActiveConnection := ADOConnection;
ADOCommand.CommandText := 'RESTORE DataBase mydb FROM DISK = ' + QuotedStr(ExpandConstant('{tmp}\mydb.bak'));
ADOCommand.CommandType := adCmdText;
ADOCommand.Execute(NULL, NULL, adCmdText or adExecuteNoRecords);
finally
ADOConnection.Close;
end;
except
MsgBox('Error', mbError, MB_OK);
end;
end;
When I run this code get this error
Exception: Microsoft OLE DB Provider for SQL Server: Cannot open backup device 'C:\Users\sina\AppData\Local\Temp\is-QADA6.tmp\mydb.bak'. Operating system error 5 (Access is denied).
How I can handle access denied in InnoSetup? I run the setup in "Run as Administrator" and turn UAC off, but I still have this problem.