From: Vikas on 8 Jun 2010 15:59 By default you wont get the ConfigurationManager. You need to add the System.Configuration DLL mannually from the Add Reference. Once you add this dll and get the ConfigurationManager, you can see the options to open the exe configuration. bz wrote: How to access app.config in a library 05-Oct-07 Hi, I have a library project that implements a Business Layer for a web and a desktop application All my business classes are in this lib, so I have here the connection string to database as app setting (in app.config The section in app.config looks like this <applicationSettings> <BB.InsuranceService.Lib.Properties.Settings> <setting name="BBAssurConnString" serializeAs="String"> <value>Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=True</value> </setting> </BB.InsuranceService.Lib.Properties.Settings> </applicationSettings> App.config belongs to project name BB.InsuranceService.Lib I have a utility class with a Static member which should return the Connection string, to use it in constuctors of BO, as below namespace BB.InsuranceService { class DBUtility { public static string ConnectionString() { return ConfigurationSettings.AppSettings.Get("BBAssurConnString"); } But I have two problems: First, I get the following warning: Warning 1 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration! System.Configuration.ConfigurationManager.AppSettings... But I cannot find ConfigurationManager, it is not in System.Configuration. Where is this? And the second problem is (and this is a problem), the call to ConfigurationSettings.AppSettings.Get("BBAssurConnString"); returns null. I have the app.config in the same folder as the library project. And as I mentioned, this library is used by two projects, a web and and win forms project. Web app has its own web.config (without any connection string setting) and Win forms project also has its own app.config file (also without any connection string setting) Can anyone help me with this, please? Thanks, Bogdan Previous Posts In This Thread: On Friday, October 05, 2007 10:35 PM bz wrote: How to access app.config in a library Hi, I have a library project that implements a Business Layer for a web and a desktop application All my business classes are in this lib, so I have here the connection string to database as app setting (in app.config The section in app.config looks like this <applicationSettings> <BB.InsuranceService.Lib.Properties.Settings> <setting name="BBAssurConnString" serializeAs="String"> <value>Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=True</value> </setting> </BB.InsuranceService.Lib.Properties.Settings> </applicationSettings> App.config belongs to project name BB.InsuranceService.Lib I have a utility class with a Static member which should return the Connection string, to use it in constuctors of BO, as below namespace BB.InsuranceService { class DBUtility { public static string ConnectionString() { return ConfigurationSettings.AppSettings.Get("BBAssurConnString"); } But I have two problems: First, I get the following warning: Warning 1 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration! System.Configuration.ConfigurationManager.AppSettings... But I cannot find ConfigurationManager, it is not in System.Configuration. Where is this? And the second problem is (and this is a problem), the call to ConfigurationSettings.AppSettings.Get("BBAssurConnString"); returns null. I have the app.config in the same folder as the library project. And as I mentioned, this library is used by two projects, a web and and win forms project. Web app has its own web.config (without any connection string setting) and Win forms project also has its own app.config file (also without any connection string setting) Can anyone help me with this, please? Thanks, Bogdan On Saturday, October 06, 2007 3:57 AM Michael Nemtsev wrote: Hello bz,use ConfigurationManager. Hello bz, use ConfigurationManager.OpenMappedExeConfiguration see the description there http://www.codeproject.com/csharp/SystemConfiguration.asp --- WBR, Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour "The greatest danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it" (c) Michelangelo b> Hi, b> b> I have a library project that implements a Business Layer for a web b> and a desktop application b> All my business classes are in this lib, so I have here the b> connection b> string to database as app setting (in app.config b> The section in app.config looks like this b> b> <applicationSettings> b> <BB.InsuranceService.Lib.Properties.Settings> b> <setting name="BBAssurConnString" serializeAs="String"> b> <value>Data Source=.\SQLEXPRESS;Initial b> Catalog=MyDB;Integrated Security=True</value> b> </setting> b> </BB.InsuranceService.Lib.Properties.Settings> b> </applicationSettings> b> App.config belongs to project name BB.InsuranceService.Lib b> b> I have a utility class with a Static member which should return the b> Connection string, to use it in constuctors of BO, as below b> b> namespace BB.InsuranceService b> { b> class DBUtility b> { b> public static string ConnectionString() b> { b> return b> ConfigurationSettings.AppSettings.Get("BBAssurConnString"); b> } b> But I have two problems: b> First, I get the following warning: b> Warning 1 'System.Configuration.ConfigurationSettings.AppSettings' is b> obsolete: 'This method is obsolete, it has been replaced by b> System.Configuration! b> System.Configuration.ConfigurationManager.AppSettings... b> b> But I cannot find ConfigurationManager, it is not in b> System.Configuration. Where is this? b> b> And the second problem is (and this is a problem), the call to b> ConfigurationSettings.AppSettings.Get("BBAssurConnString"); returns b> null. b> b> I have the app.config in the same folder as the library project. b> b> And as I mentioned, this library is used by two projects, a web and b> and win forms project. Web app has its own web.config (without any b> connection string setting) and Win forms project also has its own b> app.config file (also without any connection string setting) b> b> Can anyone help me with this, please? b> b> Thanks, b> Bogdan On Saturday, October 06, 2007 8:42 PM Mr. Arnold wrote: Re: How to access app.config in a library "bz" <bzamfir(a)gmail.com> wrote in message news:1191638125.201362.322670(a)w3g2000hsg.googlegroups.com... For the Web application, if there is not a physical separation of the tiers, meaning the Web server has the logical tiers of UI, Business, and Data Access Layer on the Web server, then Web.config can have an AppSettings in it for the SQL connection string. Web.config is the Root.Config for the entire Web application, The logical tiers will look for the AppSetting to be in the Web.config For the Windows desktop application, a DLL.Config can be applied to a DLL. The way you use a DLL.config for a DLL is the DLL.Config must be in the Windows/system32 directory where DLLHOST.exe resides that host all DLL(s). The other options you may have is to create you own DLLConfig.INI file and make your DLL get the connection string information for the INI file, or you pass the Connection string as a parameter to the Business Object. Submitted via EggHeadCafe - Software Developer Portal of Choice Telerik RadControls For Silverlight (3 and 4) Q1 2010 http://www.eggheadcafe.com/tutorials/aspnet/6566fc91-a77c-4553-8ac2-7a7fa36e63a1/telerik-radcontrols-for-s.aspx
From: Arne Vajhøj on 8 Jun 2010 19:37 On 08-06-2010 15:59, Vikas Dangwal wrote: > By default you wont get the ConfigurationManager. You need to add the System.Configuration DLL mannually from the Add Reference. Once you add this dll and get the ConfigurationManager, you can see the options to open the exe configuration. > How to access app.config in a library > 05-Oct-07 > But I cannot find ConfigurationManager, it is not in > System.Configuration. Where is this? I would think the original poster had figured it out during the two and a half year ... Arne
|
Pages: 1 Prev: downloading msdn library 2010? Next: indexof for combobox with valuemember |