Solved

Routine to create a SQL Server Backup

Posted on 2004-04-25
2
972 Views
Last Modified: 2010-04-05
I need the code (and the uses clause) to start a SQL Server backup (I will pass the Db and the Path on the server to store the backup file) I have seen the VB DMO example and I can post it here but so far I could not translate it.  It must be a full backup and it must overwrite any existing file if the names match.

One VB code example is here:
http://www.schemamania.org/jkl/booksonline/SQLBOL70/html/9_dmoe01_5.htm

Thanks,
Roberto.

0
Comment
Question by:rmaranhao
2 Comments
 
LVL 17

Accepted Solution

by:
mokule earned 250 total points
ID: 10913421
This is what I was using for BACKUP SQL Server.

//----------------------------------------------------------------
procedure TFArchiw.Button1Click(Sender: TObject);
var
  Save_Cursor: TCursor;
begin
  if not DirectoryExists(ExtractFileDir(Edit1.Text)) then
    if not CreateDir(ExtractFileDir(Edit1.Text)) then
      begin
      ModalResult := mrNone;
      exit;
      end;
  Update;
  Save_Cursor := Screen.Cursor;
  Screen.Cursor := crHourglass;
  with DM2.ADOCmd do
    begin
    CommandText := 'ArchiwEx';
    Parameters.Refresh;
    Parameters.ParamByName('@fname').Value := Edit1.Text;
    Parameters.ParamByName('@mode').Value := 2;
    Prepared := True;
    Execute;
    end;
  Screen.Cursor := Save_Cursor;
end;


//----------------------------------------------------------------
CREATE PROCEDURE ArchiwEx @fname varchar(260), @mode int  AS
IF @mode = 0
      BEGIN
      BACKUP DATABASE yourdbname TO DISK = @fname
      END
IF @mode = 1
      BEGIN
      BACKUP DATABASE yourdbname TO DISK = @fname  WITH DIFFERENTIAL
      END
IF @mode = 2
      BEGIN
      BACKUP DATABASE yourdbname TO DISK = @fname WITH INIT
      END
IF @mode = 3
      BEGIN
      BACKUP DATABASE yourdbname TO DISK = @fname  WITH DIFFERENTIAL, INIT
      END
GO
SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON
GO
0
 
LVL 5

Author Comment

by:rmaranhao
ID: 10913446
Thanks mokule. I had never found the "to disk" clause.....
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

24 Experts available now in Live!

Get 1:1 Help Now