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 procedure to call a Stored Procedure of Back End in ADO (ActiveX Data Object) and RDO (Remote Data Objects)?
What is the default Timeout for SqlCommand.CommandTimeout property?
What is ole in excel?
Can datareader hold data from multiple tables?
How do you update database through dataset?
How to work with disconnected data - the dataset and sqldataadapter?
Explain why canot we use multiple inheritance and garbage collector paralelly in .net?
Explain the two fundamental objects in ado.net?
What is the usage of the dataset object in ado.net?
What is the difference between executequery and executenonquery?
What is ado net stands for?
Describe the command object and its method.
Is datareader faster than datatable?
What is connection in ado.net?
Name which operations can you not perform on an ado.net dataset?