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

How would you connect to database using .NET?

771


Explain how to call the sql commands asynchronously in ado.net version 2.0?

695


Can datareader hold data from multiple tables?

853


Explain what are acid properties?

754


What are typed and untyped dataset?

752


What are the different methods by which we can populate a dataset?

924


Which is faster entity framework or ado.net?

682


Explain the difference in an abstract class and an interface?

692


Which is faster datareader or dataadapter?

736


Explain the advantages and disadvantages of using datalist?

785


What is the hierarchy of data in databases?

692


Which method is used by command class to execute SQL statements that return single value?

755


Data reader read and forward only, how is it possible to get 2 tables of data at a time?

667


What is a column variable?

678


How do you merge 2 datasets into the third dataset in a simple manner?

749