Question

I have 2 databases created with the exact same schema, one is made for dev and the other will be used for prod. How can I connect to the prod database when the application is released or when running in release mode. Right now I'm connected to a database through Entity Framework which uses the connection string to the dev database.

Was it helpful?

Solution

The connection string to the database is usually set in a configuration file. In your project, you have an app.config file that is copied to the output directory and renamed to match your application exe name, e.g. MyApplication.exe.config.

Basically, you have to change the connection string in this file after the deployment to your production environment. Later, if you don't have any changes to your config file in a new release, you don't need to overwrite it when you deploy the new release.

If you don't deploy your project very often or with a large number of different connection strings, you can carry out this step manually. If you want to automate this step, have a look at this link (as @abatishchev also wrote in the comments). However, keep in mind that the connection string contains sensitive information that might need to be encrypted. As you might deploy your application to several systems, it might not be possible to store an encrypted value in your rev environment that is valid on all target systems.

OTHER TIPS

To me this is a deployment question. You can use something like web deploy http://weblogs.asp.net/scottgu/archive/2010/09/13/automating-deployment-with-microsoft-web-deploy.aspx which is part of visual studio or tools such as Micorosoft's release management http://www.visualstudio.com/en-us/explore/release-management-vs.aspx or OctopusDeploy http://octopusdeploy.com/).

You can use these deployment tools to ensure that a specific version of your configuration file gets deployed to each environment. So if I was deploying to test it would deploy the test configuration. For live release it would know to deploy the release config.

You can also use powershell and other scripting tools to create scripts that will modify your config files as part of the build and release process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top