Click here to Skip to main content
11,927,711 members (50,238 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# C#4.0
Dear Friends,

Here iam developing one Application in that application there are four Projects till now iam using Four app.config file for Connection string.So now i want to use one app.config and i want to pass one connection string file in four projects.I dont know how to do if any information please share with me.


Posted 24-Sep-12 1:08am
BillWoodruff 24-Sep-12 8:13am
Please tag your question: WinForms, WPF, ASP.NET ?
Sergey Alexandrovich Kryukov 24-Sep-12 13:51pm
Sorry, what difference may it make? Config is config...
BillWoodruff 24-Sep-12 20:41pm
We're feeling the elephant in a dark room here.

There is such a range of project types, and website project types, you can create now, particularly with VS 2012: 12 options if you select File/New/Project: six options from File/New/Website.

That I assume, having created only a few of those 18 types myself, it's possible that there is a difference in types of secondary files one, or another choice, may create.

In any case shouldn't something like a "connection string" go into a resource, not a config file ?

best, Bill
Yes, that's true. Please see my comment below. With the lack of that explanation the answering would be like catching a black cat in a dark room, but the one where there is no a cat. :-)
Sergey Alexandrovich Kryukov 24-Sep-12 13:53pm
The application type probably does not matter, but you should explain your scenario and the goals. Why would you "pass" connection string? "Pass" -- from where to where?
The question might be interesting and reasonable, but right now it is not clear. Don't forget to explain your ultimate goals.
BillWoodruff 24-Sep-12 20:42pm
I also suggest you do some search on CodeProject and the Web on where a "connection string" is usually stored, and how it's accessed, based on your main and secondary project's types.
A good idea, for sure. At least it could help to make some comprehensible questions...
archanakumari 25-Sep-12 1:39am
I got a solution for this i have taken one istaller.cs file in that i have written like this

public override void Install(System.Collections.IDictionary stateSaver)
string connStr = "";
string[] strp = new
strp =Assembly.GetExecutingAssembly().Location.Split('\\');
int i = 0;
string CompletePath = "";
for (i = 0; i < strp.Length - 1; i++)
CompletePath += strp[i] + "\\";

string servername =Context.Parameters["SERVERNAME"].ToString();
string databasename =Context.Parameters["DBNAME"].ToString();
string username =Context.Parameters["UNAME"].ToString();
string password =Context.Parameters["PWDNAME"].ToString();
string EMISMIRRORSERVER =Context.Parameters["EMISMIRRORSERVER"].ToString();
string EMISWITNESSSERVER =Context.Parameters["EMISWITNESSSERVER"].ToString();
string EMISHELP = Context.Parameters["EMISHELP"].ToString();
connStr = "User Id=" + username + ";password=" + password + ";server=" + servername + ";database=" + databasename + ";Failover Partner= " + EMISMIRRORSERVER;

Configuration config = ConfigurationManager.OpenExeConfiguration(CompletePath + "DEMIS_SERVICE.exe");
config.AppSettings.Settings["DATABASE_CONNECTION"].Value = connStr;
config.AppSettings.Settings["HelpFilesLocation"].Value = EMISHELP;

Configuration config1 = ConfigurationManager.OpenExeConfiguration(CompletePath + "DEMIS_SERVER.exe");
config1.AppSettings.Settings["DATABASE_CONNECTION"].Value = connStr;
config1.AppSettings.Settings["DatabaseName"].Value = databasename;
config1.AppSettings.Settings["Witness"].Value = EMISWITNESSSERVER;
config1.AppSettings.Settings["HelpFilesLocation"].Value = EMISHELP;

Configuration config2 = ConfigurationManager.OpenExeConfiguration(CompletePath + "DEMIS_SMS_SERVICE.exe");
config2.AppSettings.Settings["DATABASE_CONNECTION"].Value = connStr;

Configuration config3 = ConfigurationManager.OpenExeConfiguration(CompletePath + "MODEM_SERVICE_DETECTOR.exe");
config3.AppSettings.Settings["DATABASE_CONNECTION"].Value = connStr;


while creating the setup i can change the connectionstring username and password of four projects at time



1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If your projects are under the same solution:
You can add you connection string in app.config in the root directory therefore you can use it in all the projects of that solution

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100