Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Import / Export IBM DB2 Database

Posted on 2008-10-02
9
Medium Priority
?
1,660 Views
Last Modified: 2012-05-05
Hello all,

I have a C# application that uses a DB2 database.  I need a method to Export and Import the entire database so that it can be ported to another computer running the same application.

I should mention that this is something that will need to be done many times by 'basic' users - so the simpler the better.

Is there a way to import / export a DB2 databse to some sort of file format?  Doe anyone have any examples.

Thanks in advance.

MAC
0
Comment
Question by:mac-will
[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
  • 5
  • 4
9 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 22623644
Hi Mac,

IBM provides several tools for backup and restore (or export and import) of databases.

The C# application probably won't come into play.  Unless you can build the command sequence into your application it will be done "offline".

The easiest and most straight-forward is to backup the entire database.  You can restore the entire database, or selected parts of it, on the target system.  The biggest requirement is that the two servers must be of similar kind.  (e.g.  You can not restore a mainframe database to a linux server.)

If you want to extract data from the source database and ADD it to existing tables on the target database, you'll probably want to use export and import.

But if you can federate the two servers (logically connect them so that they can communicate directly with each other) you can load the data into the target database with simple SQL, or either of the methods described above.


Good Luck,
Kent
0
 
LVL 8

Author Comment

by:mac-will
ID: 22623756
Hi Kent,

Thanks.   I really need to do it from the C# application and the exported database will need to eventually be put on something like DVDs.  (This needs to be done by the users of the application)

I am using DB2 - Express C, and it is generally used as a local storage database for this particular application on a windows desktop machine.

Do you have any examples of these tools?

Thanks again.

MAC
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 22623954
Hi Mac,

Ok.  The federated idea is out.  (DB2 Express has some limitations as compared with a licensed version and federating the systems is one of them.)  That's not meant to disparage DB2 -- it's still my "weapon of choice".

The DB2 command line interface will have to be installed on the client machine that is going to perform the export.  You can test to see if it's there now by opening up a command line windows and typing 'db2'.  (quit will get you out.)

In the CLI, use the EXPORT command to write the export file.  You should be able to format the EXPORT statement in C# and pass it to the function that executes shell commands.


Kent


0
Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

 
LVL 8

Author Comment

by:mac-will
ID: 22625371
Hi Kent.

Thanks again.  I am doing some reading and it looks like maybe db2move is the command I am looking for?

What is better db2 EXPORT or db2move?

Thanks,

MAC
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 22625861
DB2move is not the right tool.  It physically relocates a database (moves the data containers), when what you want to do is extract data from the database.

EXPORT is definitely the right tool here.


Kent
0
 
LVL 8

Author Comment

by:mac-will
ID: 22626002
Hmm... I just quickly tested it and it did not seem to move the original database.
the command I used is:

db2move myDB EXPORT

and it seemed to make the copy to the folder I wanted?  Finally I deleted this folder and my DB is still there.

with the db2 EXPORT I would need to specify all the tables I want to export, correct?

Thanks

MAC
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 22626673

How many tables do you want to export?
0
 
LVL 8

Author Comment

by:mac-will
ID: 22626855
This is not known yet.  Probably between 4 and 8.
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 2000 total points
ID: 22626929
Hi Mac,

According to the DB2MOVE documentation, this may in fact be the right tool.  (I've never used it in this way.)

  db2move databasename EXPORT -tn table1,table2, table3,table4


Then import the tables to the new environment with:

  db2move newdatabasename IMPORT -io replace


Assuming that you want to replace the tables and not append to them.  :)


Kent
0

Featured Post

Vim Reference Guide

Vim is a powerful text editor favored by many sysadmins and developers - here are some commands that you'll want to keep in your back pocket!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

661 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