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
What is the difference between connected and disconnected environment?
What is the difference between Datareader and Dataset?
Explain which name space is used to get assembly details?
What is ado.net and its features?
What is ado.net code?
Give an example of a .net application which connects to microsoft access database using ado.net classes.
What is difference between datareader and dataadapter?
How would you connect to a database by using .NET?
How does ado.net work?
Explain sqlconnection object?
What does sqldatareader return?
What are the namespaces used in ado.net for data access?
Which parameter of ConnectionString is used to specify the name of the database?
What is connection in ado.net?
What are the pre-requisites for connection pooling?