Multiple databases on differents servers

Posts   
 
    
bpaquin
User
Posts: 10
Joined: 05-May-2004
# Posted on: 08-Dec-2009 21:31:57   

How can I connect on two databases (same structure) but located on two differents servers?

I want to copy data from one to the other.

thanks

Benoit

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 08-Dec-2009 22:05:55   

1) Use Adapter 2) Use Adapter 3) Use Adapter

This is important simple_smile

All you need to do is create two instances of DataAccessAdapter, one pointing to each database. You can then load enties using one adapter and save them using the other one.

The trick to make sure that the entities save properly in the new database is to set .IsNew = true and .IsDirty = true on the entity and .IsChanged on each field in the entity

This will ensure that the second adapter thinks that each field needs to be saved and the entity needs to be inserted rather than updated.

Matt

bpaquin
User
Posts: 10
Joined: 05-May-2004
# Posted on: 08-Dec-2009 22:29:13   

Any way to do it with self-servicing? ;-)

Benoit

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 08-Dec-2009 23:14:14   

Erm. no - sorry - with the way SS is designed it makes this sort of data manipulation impossible.

To be honest, in 5 years of using LLBLGen professionally I've never found any situation where SelfServicing offered any advantage over adapter - the overhead in using adapter is minimal (one extra project and no lazy loading) but the flexibility it gives you is a massive advantage.

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39863
Joined: 17-Aug-2003
# Posted on: 09-Dec-2009 10:06:47   

an alternative could be the RDBMS native data import/export features. Most databases have these kind of tools which are in general very fast (as you have the same structure, so bulk copy etc. is ideal)

Frans Bouma | Lead developer LLBLGen Pro
bpaquin
User
Posts: 10
Joined: 05-May-2004
# Posted on: 09-Dec-2009 17:15:54   

What about using a transaction?


        DocumentCollection localDocs = (DocumentCollection)DocumentsDataSource.EntityCollection;


        Transaction tx = new Transaction(IsolationLevel.Serializable, "LiveData",  LiveSqlConnectionString);
        try
        {
            foreach (DocumentEntity localDoc in localDocs)
            {
                DocumentEntity liveDoc = new DocumentEntity();
                tx.Add(liveDoc);
                liveDoc.FetchUsingPK(localDoc.Id);
                liveDoc.Title= localDoc.Title;
                ...
                liveDoc.Save();
            }

            tx.Commit();
        }
        catch (Exception)
        {
           ...
        }
        finally
        {
            tx.Dispose();
        }

It does seem to work quite well, did I overlook something?

Benoit

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Dec-2009 02:41:45   

It works. The thing is how this is setup in your application context. If that application have multiple users, you might experience problems for sure. If this is just a tool that you run once, you could do what you are doing (fetch with some connection, save with another). You also could use DBUtils.ActualConnectionString for this, but transaction is a good idea to make the save action atomic.

David Elizondo | LLBLGen Support Team