Issue reading ConnectionString

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
один год назад
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?
один год назад
[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.

один год назад
Out of the box, nopC gets the connection string from:

\App_Data\appsettings.json
один год назад
But the connection string I am getting is not even in :


\App_Data\appsettings.json
один год назад
Did you customize?

In what source code file / line are you inspecting it (with debugger)?
один год назад
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.
один год назад
What nopCommerce version?
один год назад
Version 4.5xx
один год назад
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.
один год назад
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.