Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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.
 

Regards,
 
AnilKumar.D
Posted 24-Sep-12 0:08am
Comments
BillWoodruff at 24-Sep-12 8:13am
   
Please tag your question: WinForms, WPF, ASP.NET ?
Sergey Alexandrovich Kryukov at 24-Sep-12 13:51pm
   
Sorry, what difference may it make? Config is config...
--SA
BillWoodruff at 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
Sergey Alexandrovich Kryukov at 25-Sep-12 0:09am
   
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. :-)
--SA
Sergey Alexandrovich Kryukov at 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.
--SA
BillWoodruff at 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.
Sergey Alexandrovich Kryukov at 25-Sep-12 0:10am
   
A good idea, for sure. At least it could help to make some comprehensible questions...
--SA
archanakumari at 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)
{
base.Install(stateSaver);
#if DEBUG
string connStr = "";
string[] strp = new
string[Assembly.GetExecutingAssembly().Location.Split('\\').Length];
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;
config.Save();
 
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;
config1.Save();
 
Configuration config2 = ConfigurationManager.OpenExeConfiguration(CompletePath + "DEMIS_SMS_SERVICE.exe");
config2.AppSettings.Settings["DATABASE_CONNECTION"].Value = connStr;
config2.Save();
 
Configuration config3 = ConfigurationManager.OpenExeConfiguration(CompletePath + "MODEM_SERVICE_DETECTOR.exe");
config3.AppSettings.Settings["DATABASE_CONNECTION"].Value = connStr;
config3.Save();
 

#endif
}
 
while creating the setup i can change the connectionstring username and password of four projects at time
 
regards,
 
AnilKumar.D

1 solution

Rate this: bad
good
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
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 355
1 _Amy 235
2 Peter Leow 185
3 Andreas Gieriet 180
4 Dave Kreskowiak 155
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,462
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,712


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2014
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