Copy data from one DB to another?

Posts   
 
    
edalzell
User
Posts: 44
Joined: 27-May-2008
# Posted on: 04-Jun-2009 19:47:24   

I have a db (DBA) with 10 tables. However, I only use 3 of those tables for my app. I want to copy data to another DB with only those three tables and I only want a few records (~100) instead of the over 10 million records.

My thought was to fetch the data (with prefetch paths), then clone it, then write it to the other DB. I have created the new table and generated the entities, but I can't seem to copy one entity to another, even though they have the same DB fields.

Any ideas on how I can accomplish this?

I am using Version 2.6 (April 15th)

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 04-Jun-2009 22:39:17   

Do the DB's have indentical schemas, and are you using the Adapter rather than SelfServicing ? If so you should be able to load the entities from one DataAccessAdapter, clone them, and save them using a second DataAccessAdapter pointing to the second DB.

There are many threads on the forum about cloning entites without having to copy field by field, most methods utilitise XML serialisation. A search for Clone Entity should throw up something simple_smile

Matt

edalzell
User
Posts: 44
Joined: 27-May-2008
# Posted on: 04-Jun-2009 23:14:27   

Ya, I cloned them fine, but I couldn't copy them. Perhaps I did something wrong in my casting somewhere.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Jun-2009 05:08:43   

I did this some time ago. this is what I did:

  1. Create one LLBLGen project for myDB1, generate code for Adapter TemplateSet
  2. Do the same (1) with myDB2. Note that the schema should be identical.
  3. Choose one DBGeneric project (either MyDB1DBGeneric or MyDB2DBGeneric. Doesn't matter).
  4. Create a solution adding the project you pick from step 3, and the other two DBSpecific projects.
  5. Write a routine that clone an entity. This contribution is very useful: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7568
  6. Write a routine that do the following:
  7. Fetch the collectionSource with DBSpecific1
  8. collectionTarget = CloneEntityColl(collectionSource)
  9. Save the collectionTarget with DBSpecific2

Hope helpful wink

David Elizondo | LLBLGen Support Team
edalzell
User
Posts: 44
Joined: 27-May-2008
# Posted on: 05-Jun-2009 17:59:23   

OK, that is slightly different than what I did. My schemas weren't exactly the same, but I guess I could create some empty tables so that the schemas were identical.

Thanks for that.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Jun-2009 19:48:35   

At least the tables you are copying should be identical. Otherwise you will get errors at runtime simple_smile

David Elizondo | LLBLGen Support Team