If we want to connect to many databases in dataaccess layer
such as MSAccess,Sql server,oracle means not to a particular
database depends on condition we have to connect to
appropriate database in this scenario if we without changing
code Ho wdo you handle this situation?

Answers were Sorted based on User's Feedback



If we want to connect to many databases in dataaccess layer such as MSAccess,Sql server,oracle mea..

Answer / alok saxena

Hey!

You are giving clue in your question.

First We have to use select case option, In each case we
have to use respective database connection,pwd,

Mind you must have to select approrpiate provider e.x. Sql
u must use System.Data.Sql

Wish u a good luck

Is This Answer Correct ?    3 Yes 1 No

If we want to connect to many databases in dataaccess layer such as MSAccess,Sql server,oracle mea..

Answer / ganesh

Create appropriate provider at run time(use factory
patterns) based on some configurations setting (probably a
XML file).This will allow user to decide providers
dynamicallly and enable connecting to whatever database he
wants

Is This Answer Correct ?    2 Yes 1 No

If we want to connect to many databases in dataaccess layer such as MSAccess,Sql server,oracle mea..

Answer / koteswara rao.chava

SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
Get_Conn("TSQL");
//Get_Conn("ACCESS");
//Get_Conn("ORACLE");


}
protected void Get_Conn(string con_condition_Str)
{
switch (con_condition_Str)
{
case ("ACCESS"):
//SET CON = access constring
break;
case ("TSQL"):
// SET CON = SQL SERVER constring
break;
case ("ORACLE"):
// SET CON = ORACLE constring
break;
}
}

Is This Answer Correct ?    0 Yes 1 No

If we want to connect to many databases in dataaccess layer such as MSAccess,Sql server,oracle mea..

Answer / suresh jayaraman

<configuration>
<appSettings>
<add key="AccessDatabase" value="Data
Source=servername;Initial
Catalog=databasename;uid=userid;pwd=password"/>
<add key="SqlServerDatabase" value="Data
Source=servername;Initial
Catalog=databasename;uid=userid;pwd=password"/>
</appSettings>
</configuration>

and use this Key name where it is needed

If you need SqlServer DataBase

using System.Data.SqlClient;

in DataAcess Layer


public SqlConnection Connection()
{
try
{
con = new SqlConnection
(ConfigurationManager.AppSettings
["SqlServerDatabase"].ToString().Trim());

return con;

}
catch (Exception exp)
{
throw exp;
}
}

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More ADO.NET Interview Questions

What is datatable in ado.net?

0 Answers  


Describe connection object in ado.net

0 Answers  


Which method do you invoke on the DataAdapter control to load your generated dataset with data?

5 Answers   IBM, Veegyapan Impacts,


How can you identify whether or not any changes are made to the DataSet object since it was last loaded?

0 Answers  


How to call the SQL commands asynchronously in ADO.NET version 2.0

4 Answers   DELL,






If a table contains 20000 records . In a page at each time 100 records to be displayed. What are the steps u will take to improve performance? will you use dataset or datareader?

7 Answers  


What are the drawbacks of using ado.net?

0 Answers  


Where do you store connection string ?

3 Answers   Digital GlobalSoft,


What are relation objects in dataset and how & where to use them?

1 Answers  


Define executenonquery?

0 Answers  


What are the namespaces used in ado.net for data access?

0 Answers  


What are the main differences between classic ado and ado.net?

0 Answers  


Categories