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 are the steps you will take to improve performance?
What is ado asp?
Which object holds only data and does not interact with data source?
What are the namespaces used in ado.net for data access?
How can we load multiple tables in a dataset?
What is the difference between connected and disconnected environment?
How do you find the count of records in a dataset?
Which is faster sqldataadapter and sqldatareader?
What is the difference between ado.net and entity framework?
What is meant by ‘transaction’ in a database and what are the ‘properties of transaction’?
What are disadvantages of microsoft-provided data provider classes in ado.net?
What is the difference between Optimistic and Pessimistic locking?
How do you update a dataset in ado.net?
What is difference between executenonquery and executequery?
Is datareader faster than datatable?