-
August 30th, 2012, 02:39 AM
#1
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.
-
August 30th, 2012, 02:49 AM
#2
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.
-
August 30th, 2012, 02:50 AM
#3
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
-
August 30th, 2012, 03:25 AM
#4
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.
-
August 30th, 2012, 03:46 AM
#5
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
-
August 30th, 2012, 04:07 AM
#6
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 ?
-
August 30th, 2012, 08:34 AM
#7
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.
-
August 30th, 2012, 11:19 AM
#8
Re: How can I restore database from .bak file in Visual C++?
Originally Posted by shivditya
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|