Solved

Data migration using ADO.NET from a webservice

Posted on 2010-08-19
8
388 Views
Last Modified: 2012-05-10
Hi I would like to migrate data from a web service to oracle database using ADO.NET and I want to it be done in a faster way . Any help will be appreciated. I cannot do bulkcopy since I cannot access the source database, I can just get collection objects which need to be udpated in the database in efficient way (C#)

Please suggest... waiting for your reply.....
0
Comment
Question by:goldmaxhi
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:kris_per
ID: 33480209

Something like this:
using (OracleConnection connection = new OracleConnection(connectionString))

            {

                connection.Open();



                foreach(MyObject m in myCollection)

                {

                    // first col is int and other two cols are text type

                    string queryString = @"INSERT INTO Table1 (col1, col2, col3) 

                                           values ({0}, '{1}', '{2}')";

                    queryString = string.Format(queryString,

                                                m.Field1,

                                                m.Field2,

                                                m.Field3);



                    OracleCommand command = new OracleCommand(queryString);

                    command.Connection = connection;                    

                    command.ExecuteNonQuery();

                }

            }

Open in new window

0
 

Author Comment

by:goldmaxhi
ID: 33480273
Hi Kris,

Thanks for the quick response... Can we use threads for this to make it even faster something like producer /consumer model...??
0
 

Author Comment

by:goldmaxhi
ID: 33480283

I am talking about the order for million records....
0
 
LVL 16

Expert Comment

by:kris_per
ID: 33480492

Threads are mainly to provide better user experience/responsive user interface and speed is not guaranteed by using threads (as execution in cpu is switched between different threads/apps by time-slicing)

Thread can be used for the above code...one option is - all of the above can be placed in a thread which will insert row after row...

If you mean the producer /consumer model for each row, though it is possible, I am not sure about the efficiency as it would involve one connection per task. Creating and closing a connection for each task/row wont be an efficient way...again db servers will have max limit for connections (sql server has max 100 connections at a time by default)...If you think about creating one connection and using it in multiple threads..well, i am not sure how that would work...

I will go for the first option of having a thread which will have all of the above code to loop thro collection and insert rows..simple and efficient, i think may be faster than having multiple threads trying to insert...


0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Expert Comment

by:kris_per
ID: 33480525

Another improvement that will increase the efficiency is to use query string with parameters, so that it can be pre-compiled using OracleCommand.Prepare method, which I am sure will increase the speed...

0
 

Author Comment

by:goldmaxhi
ID: 33480556
Kris... thank you very much for the answer....so nice of you...
0
 
LVL 16

Accepted Solution

by:
kris_per earned 500 total points
ID: 33480584

Thanks.....

With command.Prepare method, code will be as shown below...I am sure this will be more efficient than the prev code
using (OracleConnection connection = new OracleConnection(connectionString))

            {

                connection.Open();



                // first col is int and other two cols are text type

                string queryString = @"INSERT INTO Table1 (col1, col2, col3) 

                                           values (@val1, @val2, @val3)";



                OracleCommand command = new OracleCommand(queryString);

                command.Connection = connection;

                command.Parameters.Add("@val1", SqlDbType.Int);

                command.Parameters.Add("@val2", SqlDbType.Text);

                command.Parameters.Add("@val3", SqlDbType.Text);

                command.Prepare();



                foreach(MyObject m in myCollection)

                {                    

                    command.Parameters["@val1"].Value = m.Field1;                    

                    command.Parameters["@val2"].Value = m.Field2;                    

                    command.Parameters["@val3"].Value = m.Field3;



                    command.ExecuteNonQuery();

                }

            }

Open in new window

0
 

Author Closing Comment

by:goldmaxhi
ID: 33599816
Kris was very helpful in answering the question.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now