Solved

Ado vs MSSQL 7/2k and backup/restore (500+)

Posted on 2004-04-21
10
801 Views
Last Modified: 2012-05-04
Hi out there.

Im trying to do a application witch does a backup/restore procedure. The app is multithreaded and when I restore and take a backup by ADO I would like to have a Progressbar in a Window. If i try to send the command to MS SQL by adoquery it responds that there is no answer at the adocommand. and that i should use a sqlexec command instead. anyway if i use the queryanalyzer and run the restore/backup command i get a respond telling the progress 10% complete, 20% complete osv. and I want to have this information connected to the previus mantioned progress bad. plz help me.

and excute me for my bad english.

Best regards

JGB
0
Comment
Question by:jontebgood
  • 5
  • 3
  • 2
10 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10879154
0
 

Author Comment

by:jontebgood
ID: 10885724
Hi again,
U missunderstood me, I know HOW TO do the backup up and so on. I want to catch the answer from the sql server WHEN i have sended the ado command and the job has started. if u do it with a asual ado.sql - open I get the answer that the query doesnt has any answer. if i do it with a ado.sqlexec I dont get any progress answers BUT the backup/restore starts and complete. I hope U understands me bette now.

BR
JBG
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10885914

   Yes, it is clear now.

   You can execute the ExecSQL in Thread. set the FreeOnTerminate of the thread to true. In OnTerminate event of the thread send some user message to you form where you can handle it.

   For example :

const
  WM_OPERATION_DONE = WM_USER + 1;

  TMSBackupThread = class(TThread)
  private
    SQLStatement : String;
    ParentHandle  : THandle;
    procedure ExecuteQueryOnDB (.............)
    procedure Execute;
  public
    constructor Create(OwnerFormHandle : THandle; SQLText : String; CreateSuspended : boolean = True);
  end;

  in Create you send Form1.Handle, the SQL statement. In your execute method you can take care about executing the backup / restore.

  procedure TMSBackupThread.Execute;
  begin
    // ...
    // YOUR CODE HERE
    // ...
    SendMessage(ParentHandle, WM_OPERATION_DONE, 0, 0);
  end;

  {----------------------------------------------------------------------------------------------------------------------------}

  in your form you should handle the message sent by thread :

  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure OnThreadFinished (var Msg : TMessage); message WM_OPERATION_DONE;
  public
    { Public declarations }
  end;



0
 

Author Comment

by:jontebgood
ID: 10886097
im sorry.... i have tgo refrease me becuz u dont understand me..... i will be back soon...
0
 
LVL 10

Expert Comment

by:Jacco
ID: 10890510
Hi there,

The progress is not returned as a dataset but as errormessages (with native error set to zero). The messages are issued by "print" statements. This is what OnLine books says:

"The PRINT statement takes either one character or a Unicode string expression as a parameter. It returns the string as a message to the application. The message is returned as an informational error in ADO, OLE DB, and ODBC applications. SQLSTATE is set to 01000, the native error is set to 0, and the error message string is set to the character string specified in the PRINT statement. The string is returned to the message handler call-back function in DB-Library applications."

On the ADOConnection there is an event OnInfoMessage in which the "error" is passed.

procedure TForm1.ADOConnection1InfoMessage(Connection: TADOConnection; const Error: Error; var EventStatus: TEventStatus);
begin
  Memo1.Lines.Add(Error.Description);
end;

I tested this with my version of ADODb but the event is not called... bad luck...

I will try to find if it is possible to hook the event up.

Reagrds Jacco
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 10

Expert Comment

by:Jacco
ID: 10890948
If you use a TADOCommand object it will give 1 message (but still not all and only when the command is finished...)
0
 
LVL 10

Expert Comment

by:Jacco
ID: 10891732
Got it :)

Use a TADOQuery set.

Set CursorLocation of both the TADOConnection and TADOQuery to clUseServer.

The SQL in the TADOQuery should look like this: "backup database MYDB to MYBACKUP with STATS = 1" (STATS = 1 makes sure the progress is fed back)

Now normally you would call ExecSQL but then no InfoMessages are returned. So use Open in stead then InfoMessage will be returned. (Although not all messages when the backup is very fast).

This will end in an exception which you can ignore. (By the way is you set EventStatus to esCancel then the operation is aborted!!)

Here is the dfm and pas file I used to test:

<<START OF DFM>>
object Form1: TForm1
  Left = 192
  Top = 194
  Width = 870
  Height = 640
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 88
    Top = 144
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Memo1: TMemo
    Left = 232
    Top = 24
    Width = 425
    Height = 281
    Lines.Strings = (
      'Memo1')
    TabOrder = 1
  end
  object ADOConnection1: TADOConnection
    Connected = True
    ConnectionString =
      'Provider=SQLOLEDB.1;Password=password;Persist Security Info=True' +
      ';User ID=username;Initial Catalog=TestCentral;Data Source=dsbrnd1.dsbg' +
      'roep.dsb'
    CursorLocation = clUseServer
    LoginPrompt = False
    Provider = 'SQLOLEDB.1'
    OnInfoMessage = ADOConnection1InfoMessage
    Left = 80
    Top = 56
  end
  object ADOQuery1: TADOQuery
    Connection = ADOConnection1
    CursorLocation = clUseServer
    Parameters = <>
    SQL.Strings = (
      'backup database OLAP_Dimensions to TeamGeest_Bck with STATS = 1'
      '')
    Left = 168
    Top = 56
  end
end
<<END OF DFM>>

<<START OF PAS>>
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids;

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    Button1: TButton;
    Memo1: TMemo;
    ADOQuery1: TADOQuery;
    procedure ADOConnection1InfoMessage(Connection: TADOConnection;
      const Error: Error; var EventStatus: TEventStatus);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ADOConnection1InfoMessage(Connection: TADOConnection; const Error: Error; var EventStatus: TEventStatus);
begin
  Memo1.Lines.Add(Error.Description);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ADOQuery1.Open;
end;

end.
<<END OF PAS>>
0
 

Author Comment

by:jontebgood
ID: 10899801
havent test yet but it seem to be right solution Thanks dude!!!

BR

JBG
0
 
LVL 10

Accepted Solution

by:
Jacco earned 500 total points
ID: 10900284
Hope it works for you :)

FYI I found information on the bug here:

http://support.microsoft.com/default.aspx?scid=kb;en-us;294178

Regards Jacco
0
 
LVL 10

Expert Comment

by:Jacco
ID: 10913584
Thanks man :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now