简体   繁体   中英

how to develop dbms independent application using Microsoft tech?

I need to write an app in such a way that it should not worry about the incoming DBMS. It can be Oracle, PostgreSQL, MySql etc..

The local dbms will be using SQL Server 2008 into which I will be loading data.

What is needed/planning to do...

  1. The user has textbox(s) where he is able to create/save the connection string vales in the local database/config file for each possible dbms.
  2. The application then should use this to form the connection string and connect to the incoming database one at a time or concurrently if possible.
  3. Retrieve the values and put them in the local database.
  4. No need to write data to the incoming database.Only 1-way.

In short a database independent application to only read values based on a set query and put them in the specified database.

Is it possible to do this or sounding magical?

Any solutions/sample/technique I can develop on?

Application is based on Silverlight + ASP.NET tech.

You should search and study about design patterns. check out this link . Also check out LLBLGen
If you want to opt for your own solution then you have to worked in layers. Define your Data Access Layer (DAL) loosely coupled. One way of doing it could be using interfaces. Define an Interface for database connection and then let each class for DBMS to implement it. Then you can get the database connection string on something on the following lines.
Source :

public static IDbConnection GetConnection(string connectionName)
    {
      ConnectionStringSettings ConnectString = ConfigurationManager.ConnectionStrings[connectionName];
//Use a Factory class, to which you pass the ProviderName and 
//it will return you object for that particular provider, you will have to implement it
      DbProviderFactory Factory = DbProviderFactories.GetFactory(ConnectString.ProviderName);
      IDbConnection Connection = Factory.CreateConnection();
      Connection.ConnectionString = ConnectString.ConnectionString;
      return Connection;
    }

Then you can use it like:

public static DataTable GetData()
{
  using (IDbConnection Connection = GetConnection("SiteSqlServer"))
  {
    IDbCommand Command = Connection.CreateCommand();
    Command.CommandText = "DummyCommand";
    Command.CommandType = CommandType.StoredProcedure;

    Connection.Open();

    using (IDataReader reader = Command.ExecuteReader())
    {
      DataTable Result = new DataTable();
      Result.Load(reader);
      return Result;
    }
  }
}

This is rather basic requirement and you should be able to easily fulfill it using one of the Object Relational Mapping frameworks.

If I am to recommend one - use NHibernate.

Silverlight + ASP.NET has nothing to do with the way you persist your data as long as you persist it at the server side. For the Silverlight application, you'll also need some WCF web services to communicate between the client and the server.

与其他答案一样,我强烈建议您查看以下问题https://stackoverflow.com/questions/132676/which-orm-for-net-would-you-recommend,它应该给您带来很好的休息时间那里的ORM。

To build on what the other answers have said. Think about your problem in this way.

You have "front end (asp.net/silver light)" <-> "data storage"

What you want is a step in the middle

"front end" <-> "database ignorant layer" <-> "data storage"

This middle layer may be an ORM, but all an ORM really is (besides the 100's of thousands of lines of code and years of refined experience) is an implementation of the repository and unit of work patterns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM