how to configure the project to read connection string from <connectionStrings> section of the config file and not from <appSettings>

Posts   
 
    
Alps
User
Posts: 2
Joined: 27-Sep-2007
# Posted on: 27-Sep-2007 13:30:28   

The version of LLBLGEN that I'm using is LLBLGEN Pro. version 1.0.2005.1 Final.

I would like to configure my project to read the connection string from from <connectionStrings> section of the config file and not from <appSettings>. I know that the connection string key name can be given from Main Menu > Project > Properties > Project specific properties tab > Output Settings group > ConnectionStringKeyName. But I'm unable to locate a setting to make it read from <connectionStrings> section of the config file and not from <appSettings>.

Right now the code that is generated is:

AppSettingsReader configReader = new AppSettingsReader(); return configReader.GetValue(DataAccessAdapter.ConnectionStringKeyName, typeof(string)).ToString();

===============

Instead of AppSettingsReader, since I'm placing the connection string in the <connectionStrings> section, I would like to read it from there.

any help on this is highly appreciated.

Thanks, Alpana

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Sep-2007 15:15:07   

You may manually read the connectionString in code, from the config file. And you may then set it to the (Adapter Model) DataAccessAdapter.ConnectionString which is used for the current Adapter instance only. or (SelfServicing) the DbUtils.ActualConnectionString which is used globally.

Alps
User
Posts: 2
Joined: 27-Sep-2007
# Posted on: 28-Sep-2007 16:27:02   

Walaa wrote:

You may manually read the connectionString in code, from the config file. And you may then set it to the (Adapter Model) DataAccessAdapter.ConnectionString which is used for the current Adapter instance only. or (SelfServicing) the DbUtils.ActualConnectionString which is used globally.

Hey Waala, I appreciate your immediate response on this, Many Thanks but we knew that approach before as well and we didn’t prefer and in certain cases cannot follow it for the following reasons:

  1. Setting the connection string explicitly for each DataAccessAdapter() instance would mean code change at more than 130 locations. We would prefer not to make so many code changes and if possible come up with a strategy that would require changes at fewer locations.

  2. Moreover the DataAccessAdapter() instances are also used in the auto-generated code like in the file DataAccess\Framework.LLBLGen\SqlClient\RetrievalProcedures.cs. Now since this is an autogenerated file which creates an instance of DataAccessAdapter we should not ideally manually modify this file to set the connection String

Would like to know about some setting in LLBLGEN 1.0 for this if any? or modifying manually the method ReadConnectionStringFromConfig in DataAccessAdapter.cs...

Please advice.

Looking forward for your help, Alpana

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Sep-2007 17:08:19   

Would like to know about some setting in LLBLGEN 1.0 for this if any? or modifying manually the method ReadConnectionStringFromConfig in DataAccessAdapter.cs...

For v.1.x LLBLGen could only read the connection string from the appSettings tag. This was solved in v.2.x, so you can have the connection string in the connectionStrings tag. v.2.x looks in both locations (connectionStrings first then if not found it looks in the appSettings) In both it looks for the default Main.ConnectionString key or any alternative you have set.

  1. Setting the connection string explicitly for each DataAccessAdapter() instance would mean code change at more than 130 locations. We would prefer not to make so many code changes and if possible come up with a strategy that would require changes at fewer locations.

  2. Moreover the DataAccessAdapter() instances are also used in the auto-generated code like in the file DataAccess\Framework.LLBLGen\SqlClient\RetrievalProcedures.cs. Now since this is an autogenerated file which creates an instance of DataAccessAdapter we should not ideally manually modify this file to set the connection String

Yes in v.1.x, you may manually change the ReadConnectionStringFromConfig method in the generated code, or better modify the code generation template, in order not to be overwritten when you re-generate the code.