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
Explain how to copy the contents from one table to another table and how to delete the source table in ado.net?
How to pass multiple tables in datasets simultaneously?
What are the types of databinding?
Why is ADO.NET serialization slower than ADO ?
How does entity framework work?
What does adodb stand for?
What is the namespaces being used to access oracle database?
What is dataset and datatable in ado.net?
What are the benefits of ADO.NET?
What is difference between ado.net and asp net?
Explain the difference between data reader and data set?
Can we load multiple tables in a dataset?
What is the difference between linq and ado.net?
Why do we serialize data?
Why is it important to close an ado.net application?