I have a WebForms project that has a connection string hard coded into the web.config (for Debug - web.Debug.config). This connection string points to a DB server for development.
I'd like to run a local copy of that database so that my changes don't immediately affect others.
What I've been doing is going into the web.config and updating the connection string to point to my local DB. This works, but is somewhat tedious as I have to remember to exclude the web.config and have to re-update it if I undo all changes.
Since, like I said, others are using this solution, I'd like to avoid checking anything in or modifying the web config.
Is there any way to override the web.config connection string to force the site to point to my local DB without checking anything in to source control?
One thing you might be able to do is have a separate file for your connection strings - you wouldn't check this into source control at all.
Depending on how your stuff is organized, you might need everyone who's doing development to do the same thing, and depending on how you do your publish/deploy, this may not work for you.
For example:
Web.config
<configuration>
<connectionStrings configSource="connectionstrings.config">
</connectionStrings>
</configuration>
connectionstrings.config (not in source control)
<connectionStrings>
<add name="cs" connectionString="server=.;database=whatever;"/>
</connectionStrings>
Each developer can choose which database their local machine points to, and as long as the connectionstrings.config file is not in source control (add it to the ignore list), nobody will step on each other's feet.
Create a SQL ALIAS on your local machine.
Click start run and type "cliconfg.exe" on local machine. This will help you to create a SQL Alias on your local machine. On the web.config connect to the live database but on your machine create a SQL Alias that will redirect to your local database. When this is done, when you publish the program it will automactically connect to the live database but when running from your local machine it will connect to local database without any code change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With