CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2007
    Posts
    25

    Question How can I restore database from .bak file in Visual C++?

    I have created simple database connectivity using Visual C++ 2010 professional and SQL server 2008. I want to deploy the project to other machine. I am keeping database backup file in setup.But how should I restore it programmatically ? At Present I am deploying in Computer
    where VC++2010 and SQL server 2008 is already installed.Will anyone will guide me how should
    I programmatically restore SQL Database from VC++ project.

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How can I restore database from .bak file in Visual C++?

    restoring a backup from a .BAK file is a administrative function and should be done manually from the management console.

    If you want to programmatically fill up a database, use regular SQL create/insert calls to do so.

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How can I restore database from .bak file in Visual C++?

    You can restore database only using appropriate SQL RESTORE DATABASE command.
    Victor Nijegorodov

  4. #4
    Join Date
    May 2007
    Posts
    25

    Re: How can I restore database from .bak file in Visual C++?

    Thats what I want to know What is VC++ syntax for "RESTORE DATABASE" command.If Trial.bak is my database backup what code I should write code in VC++(MFC) to restore it.
    Last edited by shivditya; August 30th, 2012 at 03:28 AM.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: How can I restore database from .bak file in Visual C++?

    There is no any " VC++ syntax" for RESTORE DATABASE. There is SQL syntax.
    To execute such an SQL statement for DB restore you will have to use some of available functions (depends on the means you are using for DB connectivity) to execute SQL commands.
    So you connect to SQL server (note that your account must have CREATE DATABASE permissions!), then call a function to execute RESTORE DATABASE SQL script...
    Victor Nijegorodov

  6. #6
    Join Date
    May 2007
    Posts
    25

    Re: How can I restore database from .bak file in Visual C++?

    Dear Sir, I am using ODBC,CRecordset(MFC class) connectivity to connect to ODBC DSN.I create DSN at runtime using SQLConfigDataSource command.
    Will you please able to tell me name Of "Some Available Function" Name to execute SQL statement of DB Restore ?

  7. #7
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How can I restore database from .bak file in Visual C++?

    the fact you want to restore a database from a .BAK means there is nothing to connect to (yet). This is why restoring from a BAK needs to be done at the management console.

    You can either use the UI to 'click your way' into doing this, or you can type the commands in the execution window of the cmanagement console. you can't do this over an ODBC connection.

    Depending on your SQL engine, there may be tools to do this remotely, and there may even be an API to do this from C++ code (remotely?). But it's not something you can do over ODBC.

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How can I restore database from .bak file in Visual C++?

    Quote Originally Posted by shivditya View Post
    Will you please able to tell me name Of "Some Available Function" Name to execute SQL statement of DB Restore ?
    You must refer to MS SQL Server documentation instead of asking on forums with unpredictable results and answer quality.

    Actually the very first skill any developer must gain is ability to find answers in official software documentation sets.
    Best regards,
    Igor

Tags for this Thread

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