Thread: Does not have Permission
 |
This question is answered.
Helpful answers available: 2.
Correct answers available: 1.
|
|
Replies:
5
-
Last Post:
Jun 8, 2017 11:01 PM
Last Post By: Bernd Maierhofer
|
|
|
Posts:
81
Registered:
2/3/02
|
|
I am using the below code to back up a Database on my local SqlExpress database.
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;
The Restore command is
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'
when I copy and paste in to management studio it restore the table with out trouble. but when I run this code I get an E,Message of 'User does not have permission to RESTORE database ''score_import''' SA has full permission. Any idea what I am missing. Delphi XE6, Windows10 Sql2012
Thank
Donald S. Bossen
|
|
|
Posts:
161
Registered:
9/27/99
|
|
Isn´t there a
ConnectionMaster.Connected := True;
missing?
And there for the error message is misleading?
HTH Bernd
|
|
|
|
Posts:
81
Registered:
2/3/02
|
|
Isn´t there a
ConnectionMaster.Connected := True;
missing?
And there for the error message is misleading?
HTH Bernd
Thank you for your reply
I have tried it connect = true and connect = false to no difference.
I have been experimenting and learned something I did not think mattered this code is part of a service designed to replace this database.
If I drop a ADOConection and a ADOCommand on the form and copy the connection string and command string the restore works so there seems to be no problem in the string and more a problem with the fact it is in a service.
|
|
|
|
Posts:
161
Registered:
9/27/99
|
|
Donald Bossen wrote:
Isn´t there a
ConnectionMaster.Connected := True;
missing?
And there for the error message is misleading?
HTH Bernd
Thank you for your reply
I have tried it connect = true and connect = false to no difference.
I have been experimenting and learned something I did not think
mattered this code is part of a service designed to replace this
database. If I drop a ADOConection and a ADOCommand on the form and
copy the connection string and command string the restore works so
there seems to be no problem in the string and more a problem with
the fact it is in a service.
Maybe the server is not configured to allow a connection via SA, but
only thru Windows Mode.
Bernd
--
|
|
|
|
Posts:
81
Registered:
2/3/02
|
|
Donald Bossen wrote:
Isn´t there a
ConnectionMaster.Connected := True;
missing?
And there for the error message is misleading?
HTH Bernd
Thank you for your reply
I have tried it connect = true and connect = false to no difference.
I have been experimenting and learned something I did not think
mattered this code is part of a service designed to replace this
database. If I drop a ADOConection and a ADOCommand on the form and
copy the connection string and command string the restore works so
there seems to be no problem in the string and more a problem with
the fact it is in a service.
Maybe the server is not configured to allow a connection via SA, but
only thru Windows Mode.
Bernd
--
I was thinking along those lines. Thanks to Embarcadero Support. He was to duplicate my problem and solved it by Removing from the connection string Integrated Security="" If you are interested in why do a google search for ADO Integrated Security.
thanks for every ones help
Donald S. Bossen
|
|
|
|
Posts:
161
Registered:
9/27/99
|
|
Donald Bossen wrote:
Donald Bossen wrote:
Isn´t there a
ConnectionMaster.Connected := True;
missing?
And there for the error message is misleading?
HTH Bernd
Thank you for your reply
I have tried it connect = true and connect = false to no
difference. I have been experimenting and learned something I
did not think mattered this code is part of a service designed to
replace this database. If I drop a ADOConection and a ADOCommand
on the form and copy the connection string and command string the
restore works so there seems to be no problem in the string and
more a problem with the fact it is in a service.
Maybe the server is not configured to allow a connection via SA, but
only thru Windows Mode.
Bernd
--
I was thinking along those lines. Thanks to Embarcadero Support. He
was to duplicate my problem and solved it by Removing from the
connection string Integrated Security="" If you are interested in why
do a google search for ADO Integrated Security. thanks for every
ones help Donald S. Bossen
 This would have been my next guess. Tx for sharing.
Bernd
--
|
|
|
|
Legend
|
|
Helpful Answer
(5 pts)
|
|
Correct Answer
(10 pts)
|
|
Connect with Us