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
How would you connect to database using .NET?
Explain how to call the sql commands asynchronously in ado.net version 2.0?
Can datareader hold data from multiple tables?
Explain what are acid properties?
What are typed and untyped dataset?
What are the different methods by which we can populate a dataset?
Which is faster entity framework or ado.net?
Explain the difference in an abstract class and an interface?
Which is faster datareader or dataadapter?
Explain the advantages and disadvantages of using datalist?
What is the hierarchy of data in databases?
Which method is used by command class to execute SQL statements that return single value?
Data reader read and forward only, how is it possible to get 2 tables of data at a time?
What is a column variable?
How do you merge 2 datasets into the third dataset in a simple manner?