CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2008
    Posts
    61

    How to backing up dataBase using C# Code ?

    Hi there, I have a database named : "ClinicDB.MDF"
    I want to getting backup of this database with C# Code ...
    i saw it's SQL Syntax,
    here's an example of MSDN Library :

    Code:
    BACKUP DATABASE AdventureWorks 
     TO DISK = 'Z:\SQLServerBackups\AdvWorksData.bak'
       WITH FORMAT;
    GO
    when I changed the dataBase name adventureWorks to ClinicDB and execute it, I got no answer ...
    this is the SQL Server management studio Error :

    Code:
    Msg 102, Level 15, State 1, Line 1
    Incorrect syntax near '.'.
    Msg 319, Level 15, State 1, Line 3
    Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
    and finally I want a code that can be run in C# and getting a backup dataBase operation, but I don't know how to code it ...

    thanks if someone help ...

  2. #2
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: How to backing up dataBase using C# Code ?

    as the error message says it is expecting semicolon ; - before the
    [CODE]WITH FORMAT[\CODE]

    statement, try giving that
    Last edited by vcdebugger; July 21st, 2009 at 05:12 AM.

  3. #3
    Join Date
    Feb 2009
    Location
    Atlanta, GA
    Posts
    17

    Re: How to backing up dataBase using C# Code ?

    Code:
    BACKUP DATABASE [DataBaseName] TO  DISK = 'C:\Program Files\...\db.bak' WITH  INIT ,  NOUNLOAD ,  NAME = N'DataBaseName backup',  NOSKIP ,  STATS = 10,  NOFORMAT
    Scott Knake
    Custom Software Development
    Apex Software, Inc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured