Runtime connection string

Posts   
 
    
GregCSharp
User
Posts: 45
Joined: 18-Nov-2013
# Posted on: 29-Jan-2020 19:10:10   

Hi,

I use C# Webform for the web app. I am not sure where i have to specify the connection string for the runtime and while debuggin locally, i keep getting an error saying

No connection string specified. Please specify a connection string in the app/web.config file or through the RuntimeConfiguration system.

I tried in different spot in the web.config file under runtime > connectionStrings adding <add name="llblgen" providerName="System.Data.SqlClient" connectionString="stringhere" /> in the Global.asax file on Application_Start adding RuntimeConfiguration.AddConnectionString in the page itself adding RuntimeConfiguration.AddConnectionString

The documentation does not explain enough to me and I am not sure where to add the connection string

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 29-Jan-2020 23:58:28   

How the framework would recognize the connetionString you have provided? The answer is: it needs to have a specific name recognized by the framework.

Please read carefully this section of the documentation.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 30-Jan-2020 09:43:49   

So in short:

instead of: "llblgen" in: <add name="llblgen" providerName="System.Data.SqlClient" connectionString="stringhere" />

use the name as specified in the connectionstring line as generated in the app.config in the generated code. The 'name' is important, as the name is known by the generated code so you can't just make up any name, it has to match. The one in the app.config file has the right name. You can then alter the actual connection string in the 'connectionString=""' section as you wish.

By default the name is "ConnectionString.SQL Server (SqlClient)". 'providerName' isn't used.

Frans Bouma | Lead developer LLBLGen Pro
GregCSharp
User
Posts: 45
Joined: 18-Nov-2013
# Posted on: 30-Jan-2020 16:46:23   

Thanks for both of your answers.

Walaa, I read carefully the section your pointed out. I did find that in the project settings, there is a setting for connection string key name pattern which is Main.ConnectionString.{$ProviderName}. However, no where in the documentation I see where to drop the line RuntimeConfiguration.AddConnectionString("Key", "ConnectionString");

Otis, In my class library app.config file I now have


<?xml version="1.0"?>
<configuration>
    <connectionStrings>
        <add name="Main.ConnectionString.SQL Server (SqlClient)" connectionString="data source=xxx.xxx.x.xxx,xxx;initial catalog=dbname;User ID=idname;Password=pwd;persist security info=False"/>
    </connectionStrings>
  <runtime>
    <connectionStrings>
        <add name="Main.ConnectionString.SQL Server (SqlClient)" connectionString="data source=xxx.xxx.x.xxx,xxx;initial catalog=dbname;User ID=idname;Password=pwd;persist security info=False"/>
    </connectionStrings>
  </runtime>
</configuration>


but i still get the error No connection string specified at the first call to the database

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 30-Jan-2020 17:01:39   

The connection strings should be in the web.config file, namely the one of your application, not the one in the class library simple_smile We generate that one (the generated app.config file in DbSpecific) to make it easy to copy/paste it over to your own application's web/app.config file.

You have either configuration file configuration (normally the way to go for .net full projects) or RuntimeConfiguration configuration (the way to go in .net core applications but also works on .net full applications).

If you use the web.config file then you don't need to use RuntimeConfiguration. If you want to use the RuntimeConfiguration system, you can use that and then you don't need to store information in web/app.config files.

The line: RuntimeConfiguration.AddConnectionString("Key", "ConnectionString");

has to be run as soon as the app starts, see: https://www.llblgen.com/Documentation/5.6/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/gencode_runtimeconfiguration.htm#runtimeconfiguration-and-application-startup

Frans Bouma | Lead developer LLBLGen Pro