Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 03-26-2018, 10:23 AM
rmt rmt is offline
Senior Member
 
Join Date: Jun 2013
Posts: 267
Default Delphi5: Retrieve Messages returned while executing SQL command

Dear Expert,

How to read the Messages returned when SQL Query is executed from Delphi5 using TClientDataSet in case when Result Sets are not returned.

Suppose we are executing following SQL query from Delphi Application:

restore verifyonly from disk ='E:\TEST.BAK'

Now the following Messages will be returned:

'The backup set on file 1 is valid.'

Kindly help to trace this message.

Thanks in advance.
__________________
Rmt
  #2  
Old 03-26-2018, 12:03 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,269
Default

From a ClientDataSet I'm not sure how to do that, also if that's even possible.

But you could do it on a TADOConnection/TADOQuery.
Implement the ADOConnecction.OnInfoMessage, trick is that what you're looking for is in the Error.Description, so don't let that fool you...
  #3  
Old 03-27-2018, 04:14 AM
rmt rmt is offline
Senior Member
 
Join Date: Jun 2013
Posts: 267
Default

Dear Norrit,

Thanks for the suggestion. I tried as below, but I could not get any message.

HTML Code:
procedure TfrmVerifyDataBackup.btnVerifyClick(Sender: TObject);
begin
try
try
screen.Cursor:=crHourGlass;
with ADOQueryVerifyDataBackup do
                begin
                Active:=False;
                sql.clear;
                SQL.add('restore verifyonly from disk ='+QuotedStr(editPath.Text)+' select 1');
                Active:=True;

                end;
btnVerify.Enabled:=False;
except raise ;
screen.Cursor:=crDefault;
end;
finally
screen.Cursor:=crDefault;
end;
end;

procedure TfrmVerifyDataBackup.ADOConnection1InfoMessage(
  Connection: TADOConnection; const Error: Error;
  var EventStatus: TEventStatus);
begin
ShowMessage(Error.Description);
end;
__________________
Rmt
  #4  
Old 03-27-2018, 09:36 AM
rmt rmt is offline
Senior Member
 
Join Date: Jun 2013
Posts: 267
Default

Dear Expert,

Thanks for all help. But I coded as below and worked as desired.

HTML Code:
procedure TfrmVerifyDataBackup.btnVerifyClick(Sender: TObject);
//var n:Integer;
var cmd: _Command;
    Conn: _Connection;
    Pars: Parameters;
    RA: OleVariant;
    n: Integer;
 WindowsUser,MBUdlName:String;
begin

Memo1.Clear;

        Conn:= CreateComObject (CLASS_Connection) as _Connection;

        WindowsUser:=GetUserFromWindows;
        if FileExists(DataLinkDir+'\Connection.Config') then
                MBUdlName:=WindowsUser+'.udl'
        else
                MBUdlName :='Microbanker.udl';

        Conn.ConnectionString :=format('FILE NAME=%S\'+MBUdlName,[DataLinkDir]);

        Conn.Open(Conn.ConnectionString, '' , '' , Integer (adConnectUnspecified));

        cmd:= CreateComObject (CLASS_Command) as _Command;
        cmd.CommandType:= adcmdText;//adCmdStoredProc;
        cmd.Set_ActiveConnection (Conn);
        Pars:= cmd.Parameters;
        Pars.Append (cmd.CreateParameter ( '@RETURN' , adInteger, adParamReturnValue, 4 , 0 ));

        cmd.CommandText:='restore verifyonly from disk ='+QuotedStr(editPath.Text);
        //cmd.Execute (RA, Pars, Integer (adCmdStoredProc));
        cmd.Execute(RA,Pars,Integer(adcmdText));

        for n:= 0 to (Conn.Errors. Count - 1 ) do
        begin
                Memo1.Lines.Add (Conn.Errors.Item [n] .Description);
        end ;

        cmd.Set_ActiveConnection (nil);
        Conn.Close;
        Pars:= nil;
        cmd:= nil;
        Conn:= nil;
end;
Thanks..
__________________
Rmt
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 07:48 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.