I am new to ASP.Net web app development and I am trying to learn.
I have a ASP.NET web app where a specific connection string is used when debugged (pressing F5). Below are the connection strings and app settings in Web.config file:
<appSettings>
<add key="Environment" value="TEST"/>
</appSettings>
<connectionStrings>
<add name="TEST" connectionString="Server=mySQLExpressServerAddress;Database=myDataBase;Trusted_Connection=True;" />
<add name="DEV" connectionString="a connection to the test server db" />
<add name="PROD" connectionString="a connection to the prod server db" />
</connectionStrings>
Till here, when I debug (pressing F5). The execution is smooth.
When I comment out the TEST from connection string, and add a secondary connection string like this:
<appSettings>
<add key="Environment" value="TEST"/>
</appSettings>
<connectionStrings>
<!-- <add name="TEST" connectionString="Server=mySQLExpressServerAddress;Database=myDataBase;Trusted_Connection=True;" /> -->
<add name="TEST_TWO" connectionString="Server=mySQLExpressServerAddress;Database=myDataBase;Trusted_Connection=True;" />
<add name="DEV" connectionString="a connection to the test server db" />
<add name="PROD" connectionString="a connection to the prod server db" />
</connectionStrings>
and debug the app (pressing F5), there is a null pointer exception. The execution detail is as follows:
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Now, if I change the value of environment in app settings from test to test_two (while leaving the commented TEST connection string as it is) like this:
<appSettings>
<add key="Environment" value="TEST_TWO"/>
</appSettings>
<connectionStrings>
<!-- <add name="TEST" connectionString="Server=mySQLExpressServerAddress;Database=myDataBase;Trusted_Connection=True;" /> -->
<add name="TEST_TWO" connectionString="Server=mySQLExpressServerAddress;Database=myDataBase;Trusted_Connection=True;" />
<add name="DEV" connectionString="a connection to the test server db" />
<add name="PROD" connectionString="a connection to the prod server db" />
</connectionStrings>
and debug the app (pressing F5), the execution is smooth.
I believe, the "Environment" key from app settings is used to identify the connection string while debugging. I want to know if I am correct or wrong here.
If I am wrong, how can I assign a particular connection string for debugging.
Thank You