?
Solved

Routine to create a SQL Server Backup

Posted on 2004-04-25
2
Medium Priority
?
1,093 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
mokule earned 1000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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