Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Please Can anyone help me ? I want to take backup and restore all types of database(MySQL, SQL Server, MS SQL, MS Access, Oracle and DB2) in C# Windows Application. I can successfully take backup and restore MySQL and SQL Server, don't
for Oracle and DB2. Please help me by giving links or source code.

Thanks in Advance.

Tristan
Posted
Updated 12-Jul-11 18:41pm
v3
Comments
Dr.Walt Fair, PE 12-Jul-11 23:25pm    
What specific problems are you having with Oracle, DB2, etc? I doubt anyone will just up and give you code.
TMSRANA 13-Jul-11 0:15am    
I want Source code in C# because I could not find any code for Oracle and DB2 Please help me.
Al Moje 13-Jul-11 0:44am    
How far have you done in trying? Can you show us your code, and the problem you have encountered? Is problem encountered when processing is too long and has a Time out?
TMSRANA 13-Jul-11 1:27am    
Dear Sir,
I think U could not understand what i have said.
There are no source code for Oracle and DB2 Backup/Restore written in C#.
I just need the source code for taking backup and restoring Oracle and DB2 Database in C# Windows Application.
sadlinus 19-May-12 3:21am    
Hey can i know how u can take backup and restore from windows mobile using sql server can u point to the resource for it. i need procedure and code. pls help

This Would Work for Oracle database:

C#
OledbCommand cmd=new OledbCommand ("backup database databasename to disk ='C:\databasename.bak'",con);
con.open();
cmd.ExecutenonQuery();
con.close();
 
Share this answer
 
v3
Hi,

In addition to Ger Hayden Solution, you must also
consider the Time out, cause backup sometimes take
too long.

Example code:

In your Web.config you have:
<add name="ClaimsORAConnection" connectionString="Provider=MSDAORA;Data Source=Your serverName;User ID=YourUserId;Password=YourPassword"/>



and then in your code behind:
OleDbCommand ocmd = new OleDbCommand();

string strConn = ConfigurationManager.ConnectionStrings["ClaimsORAConnection"].ConnectionString.ToString();
OleDbConnection aConn = new OleDbConnection((strConn + ";Connection Timeout=300; pooling='true';Max Pool Size=300"));

string strQry = "backup database databasename to disk ='C:\databasename.bak'"
try
{
   ocmd.CommandTimeout = 300;
   ocmd = new System.Data.OleDb.OleDbCommand(strQry, aConn);
   ocmd.ExecuteNonQuery();
}
catch (Exception)
{
    return "Backup process failed...";
}
finally
{
   ocmd.Dispose();
   aConn.Close();
}


The Connection Timeout should be fair with Command Timeout otherwise
process catch Timeout.

You may adjust the Time out duration from 300 or more,
depending in time of process


Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Hope this could help.


Regards,

Algem
 
Share this answer
 
v4
Comments
TMSRANA 13-Jul-11 1:32am    
No This is not Web. This is only Desktop Solution.
TMSRANA 13-Jul-11 1:38am    
What do u my by ClaimsORAConnection
Al Moje 13-Jul-11 2:03am    
Hi,

ClaimsORAConnection is a connection defined in your config.
<connectionstrings>
<!-- it is here -->
</connectionstrings>
Al Moje 13-Jul-11 2:16am    
If you have a Toad server utility:
try to execute this:
backup database Yourdatabasename to disk ='C:\Targetdatabasename.bak'
TMSRANA 13-Jul-11 2:42am    
Dear Sir,
Please give me namespaces according to this action or If U have any demo then U can send me.
Thanks
try using the class I posted here http://g4ac.co.za/RjwyM[^]
 
Share this answer
 
Comments
sadlinus 19-May-12 3:22am    
Hey can i know how to take backup and restore from windows mobile to sql server can u point to the resource for it. i need procedure and code. pls help
You don't need the source code - use the documentation that came with each database to find the specific command for export / dump e.g. mysqldump and string it into something like cmd.CommandText then execute it with something line cmd.ExecuteScalar(), where cmd is defined as
Sql cmd = new SqlCommand
.

Repeat for each database.

There are also more crude work arounds that you can do in code like select * from each table and hold the result in a csv file.
 
Share this answer
 
Hi,

ClaimsORAConnection is an oracle connection string defination in config file

<add name="ClaimsORAConnection" connectionString="Provider=MSDAORA;Data Source=Your serverName;User ID=YourUserId;Password=YourPassword"/>



ClaimsORAConnection is a connection defined in your config.
<connectionStrings>
   <!-- it should be here -->
</connectionStrings>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900