Quantcast
Viewing all articles
Browse latest Browse all 10

Making ASP.NET Application Which Supports Any Type of Database Server

Hi,

 

If anyone needs to develop an asp.net web appliction which supports more than one database like oracle and sql server.One thing you have to do is have connection strings for both database server with provider name in it just comment the connection string for which database you don't want to use in the application.

Now create saperate classes which have the functions for saperate database named DA_SQL and DA_Oracle and a Interface class between them named like IDA which has all the function definition and they are implemented in the classes of sql and oracle.

Now you have to create a constructor of interface class which decides which class to be used according to connection string like this.

public IDA CreateDBObject()
        {
            //Get Provider Name
            IDA obj = null;
            String strProviderName =

ConfigurationManager.ConnectionStrings["conn"].Pr

oviderName;
            if (strProviderName ==

"System.Data.OracleClient")
            {
                obj = new DA_Oracle();
            }
            if (strProviderName ==

"System.Data.SqlClient")
            {
                   
                obj = new DA_Sql();
            }
            return obj;
        }

From the business logic or page you have to create the object of the interface class and execute the function of that interface the constructor will decide which database server to be used and executes the function for that class.

 


Viewing all articles
Browse latest Browse all 10

Trending Articles