开发者

Multiple Database updates in single application

I want to build a small .net application which can update multiple databases with same data. This will be some sort of automated appication. I have some idea in mind but I am lo开发者_运维问答oking for some ideas from senior ppl before starting development on it. Please share your views.

Appreciate your help. Thanks !!


From the low level view, it should enumerate all target databases and save changes to them.

From the architectural perspective, you should think of proxy design pattern usage. Thus, you will use the abstraction IDatabase in your app, but will switch from proxy to the single database implementation at any time:

// database abstraction
interface IDatabase
{
    void SaveSomeData(IData data);
}

// example of implementation
class SQLDatabase : IDatabase
{
    public SQLDatabase(string connection)
    {...}

    abstract void SaveSomeData(IData data)
    {
        // establish db connection using given connection and run sql queries against it.
    }
}

// proxy which can save data to several databases.
class DatabaseSaver : IDataBase
{
    private IDatabase[] _databases;

    public DatabaseSaver(IDatabase[] databases)
    {
        _databases = databases;
    }

    void SaveSomeData(IData data)
    {
        foreach(var db in _databases)
            db.SaveSomeData(data);
        // TODO: error handling situations are omitted.
    }
}

I hope this helps!


You could use DataSets

These can be serialized, and then applied to another database. Assuming that all target databases are in synch this should work without too many problems. You will have to refrain from using stored procedures and other 'interactive' database features though.

Essentially you will use the dataset in offline mode, and later apply the changes to 'a' database. Repeat that and you will update 'the' databases.

Note that you are most likely better served with some DB-level replication (Mysql, Postgresql, Oracle, SQLServer all support this in one way or another)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜