Click here to Skip to main content
15,912,493 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Suppose I provide two connection strings web.config then how can we recognize which connection was open in C#

By the code:
myconnection.open();
myconnection.close();

How to open particular connection


Abhishek Sur
Thanks for help but plz provide little examle in c#
how connect connection first connection
after that
connection to second connection

Wating reply.....
Posted
Updated 3-Feb-10 0:03am
v3

Ganesh_verma wrote:
Thanks for help but plz provide little examle in c#


It's not our fault that you are stupid. Every answer you have is correct, they just assume a very basic level of competence. You need to write your code to address your connection strings by name or by index, then write the code to make the right calls to each DB, based on the two connection strings. A more specific example both should not be needed, and is impossible without seeing your config file.
 
Share this answer
 
You can run the code (in C#):
string
strConn=ConfigurationSettings.AppSettings["ConnectionString"];
 
Share this answer
 
Name each connectionstring and call it by name.

ConfigurationManager.ConnectionStrings["con1"].ConnectionString


like this.

If you still want the index based connectionstring, it will call according to the sequence mentioned in the web.config.
 
Share this answer
 
If you have two connection strings, you'd have to specify in your code which one you were using. It isn't going to magically choose one or the other if they are named the same thing, it's going to give an error. If they are not named the same, you'll access them by name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900