Say we have Four different Databases and their connections as well which are stored in configuration file like web.Config or
<App-Name>.config and we are in need to connect to different database depending upon user type
User ID=admin;Initial Catalog=biblio;Data Source=betav9;
Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;
Workstation ID=BETAV9;Use Encryption for Data=False;
Tag with column collation when possible=False"/>
When we have taken a decision over user type, we may pass a value to if else structure or case. Depending upon the value you can get the type of connection to
a database we want.
Object dbCon = null;
switch(userType)
{
case "sqlConnection"
dbCon = new SqlConnection("SqlServerConString");
// provide appropriate sql command
break;
case "OleDbConnection"
dbCon = new System.Data.OleDb.OleDbConnection("OleDbConString");
// provide appropriate sql command
break;
case "OdbcConnection"
dbCon = new OdbcConnection("OdbcCongString");
// provide appropriate sql command
break;
case "OracleConnection"
dbCon = new OleDbConnection ("OracleConString");
// provide appropriate sql command
break;
}