Issue reading ConnectionString

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 year ago
I added connection string in web.config.
<ConnectionStrings>
    <add name="DB1" connectionString="server=1.12.123.1234;database=database1;allowuservariables=True;user id=remoteUser;password=tmppassword123;" />
    <add name="DB2" connectionString="server=localhost;database=carpartstore;allowuservariables=True;user id=root;password=tmppassword123;"/>
  </ConnectionStrings>



And in HomeController.cs :

        public static string conSTring = System.Configuration.ConfigurationManager.ConnectionStrings["DB1"].ConnectionString;


but conSTring is NULL and creates exception when I try to create MYSQLCONNECTION.


What am I missing here?
1 year ago
[quote=ehsankayani]I added connection string in web.config.
<connectionStrings>
    <add name="DB1" connectionString="server=1.12.123.1234;database=database1;allowuservariables=True;user id=remoteUser;password=tmppassword123;" />
    <add name="DB2" connectionString="server=localhost;database=carpartstore;allowuservariables=True;user id=root;password=tmppassword123;"/>
  </connectionStrings>


And in HomeController.cs :

        public static string conSTring = System.Configuration.ConfigurationManager.ConnectionStrings["DB1"].ConnectionString;


but conSTring is NULL and creates exception when I try to create MYSQLCONNECTION.


It is however picking some connectionString but its not what's in config.

1 year ago
Out of the box, nopC gets the connection string from:

\App_Data\appsettings.json
1 year ago
But the connection string I am getting is not even in :


\App_Data\appsettings.json
1 year ago
Did you customize?

In what source code file / line are you inspecting it (with debugger)?
1 year ago
Well I have don't a lot of customization but did not change anything in web.config  until now.
Just added a connection string to get it in HomeController.cs which made sense. But it does not get it in fact is getting some other ConnectionString which I cannot find in the Entire Solution.
1 year ago
What nopCommerce version?
1 year ago
Version 4.5xx
1 year ago
In 4.50, app configuration can be stored in a file (generic "App_Data/appsettings.json" or environment-specific e.g. "App_Data/appsettings.development.json") or in environment variables.
To access the configuration, use the appropriate "IConfig" object, such as "DataConfig" for access to the connection string, see an example here.
1 year ago
Yes, But why we have a web.config if its not used :| ...
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.