Issue reading ConnectionString

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 1 an
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?
Il y a 1 an
[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.

Il y a 1 an
Out of the box, nopC gets the connection string from:

\App_Data\appsettings.json
Il y a 1 an
But the connection string I am getting is not even in :


\App_Data\appsettings.json
Il y a 1 an
Did you customize?

In what source code file / line are you inspecting it (with debugger)?
Il y a 1 an
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.
Il y a 1 an
What nopCommerce version?
Il y a 1 an
Version 4.5xx
Il y a 1 an
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.
Il y a 1 an
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.