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?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between connected and disconnected environment?

487


What is the difference between Datareader and Dataset?

534


Explain which name space is used to get assembly details?

522


What is ado.net and its features?

493


What is ado.net code?

515






Give an example of a .net application which connects to microsoft access database using ado.net classes.

580


What is difference between datareader and dataadapter?

542


How would you connect to a database by using .NET?

471


How does ado.net work?

486


Explain sqlconnection object?

528


What does sqldatareader return?

499


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

475


Which parameter of ConnectionString is used to specify the name of the database?

542


What is connection in ado.net?

525


What are the pre-requisites for connection pooling?

529