Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Does not have Permission


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Jun 8, 2017 11:01 PM Last Post By: Bernd Maierhofer
Donald Bossen

Posts: 81
Registered: 2/3/02
Does not have Permission  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 2, 2017 2:39 PM
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
Bernd Maierhofer

Posts: 161
Registered: 9/27/99
Re: Does not have Permission  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2017 1:07 AM   in response to: Donald Bossen in response to: Donald Bossen
Isn´t there a
ConnectionMaster.Connected := True;
missing?

And there for the error message is misleading?

HTH Bernd
Donald Bossen

Posts: 81
Registered: 2/3/02
Re: Does not have Permission  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2017 8:32 AM   in response to: Bernd Maierhofer in response to: Bernd Maierhofer
Bernd Maierhofer 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.
Bernd Maierhofer

Posts: 161
Registered: 9/27/99
Re: Does not have Permission  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2017 10:55 PM   in response to: Donald Bossen in response to: Donald Bossen
Donald Bossen wrote:

Bernd Maierhofer 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

--
Donald Bossen

Posts: 81
Registered: 2/3/02
Re: Does not have Permission  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 8, 2017 10:48 AM   in response to: Bernd Maierhofer in response to: Bernd Maierhofer
Bernd Maierhofer wrote:
Donald Bossen wrote:

Bernd Maierhofer 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
Bernd Maierhofer

Posts: 161
Registered: 9/27/99
Re: Does not have Permission  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 8, 2017 11:01 PM   in response to: Donald Bossen in response to: Donald Bossen
Donald Bossen wrote:

Bernd Maierhofer wrote:
Donald Bossen wrote:

Bernd Maierhofer 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)

Server Response from: ETNAJIVE02