App.config and User Controls

Posts   
 
    
jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 08-Nov-2003 10:20:47   

Anyone try to encapsulate data access into a user control and get problems with accessing the connection string?

I get the following error at **DESIGN TIME **when trying to drag the user control to my form: An exception occurred while trying to create an instance of Herzog.HITS.HITSctls.DayListBox. The exception was "The key 'Main.ConnectionString' does not exist in the appSettings configuration section.".

I can verify that App.config exists and has been added to just about every freakin' project in the solution...not that I needed to go that far as data access hasn't been a problem up to this point. A Google Groups search hasn't netted me anything...any thoughts?

Jeff...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39873
Joined: 17-Aug-2003
# Posted on: 08-Nov-2003 11:40:35   

For what I could find, a developer should set 'dynamic properties' for the control in the properties tab of visual studio to tell visual studio that the property is read from the configuration file. I think you should set (haven't tried it) a dynamic property on the control called Main.ConnectionString and give it the value in the config file.

At the moment having generated classes as components is not fully supported, as I have to implement an interface for that, IComponent. This will be done for the 2nd template set, which will also get IXmlSerializable support, late November.

Let me know if Dynamic Properties do work or not. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
dava avatar
dava
User
Posts: 9
Joined: 17-Sep-2003
# Posted on: 08-Nov-2003 15:55:22   

Make sure you're Web.Config has the connection string in the <appSettings> section i.e.

<configuration> <appSettings> <add key="Main.ConnectionString" value="server=localhost;database=MyDB;uid=MyUser;pwd=MyPassword"/>

Other user settings....

</appSettings> <system.web> ...

swallace
User
Posts: 648
Joined: 18-Aug-2003
# Posted on: 08-Nov-2003 17:53:41   

For some reason those settings do not cross from child assembly to parent assembly, meaning, if you have a setting in the user control, the control only tries to read it from the parent assembly's web.config (or app.config). Duplicate the setting in the parent assembly (application's) config file.

Sure it's weird. Sure it's annoying. Get over it. simple_smile

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 12-Nov-2003 10:32:49   

Haven't trolled the boards for a bit so I hadn't seen the responses. I ended up duplicating code for the two times I needed the control so I haven't had a chance to work with the dynamic property yet.

As for whether the app.config file is in the right place and has the right format:it is and it does...no dice. Thanks

Jeff...