Entity Framework webapi c# connection string change

.net asp.net-web-api c# entity-framework-6

Question

We are using the .Net C# Web API using Entity framework for DAL (Data Accesss layer). We have to do development by connecting the Development/testing DB server. Now we need to change the DB server from Development to Production. Is that possible to change only the Connection string and connect to Production DB server. Anything additionally need to be taken care. Please help.

1
0
9/25/2018 10:59:11 PM

Accepted Answer

Add web.config file transforms.

When you deploy a Web site/Web API, you often want some settings in the deployed application's Web.config file to be different from the development Web.config file. For example, you might want to change connection strings so that they point to different databases.

If you want to create a transform file for a custom build configuration that does not exist, create the build configuration first by using Configuration Manager.

You can open Configuration Manager by selecting it from the Build menu. For more information, see Configuration Manager Dialog Box.

In Solution Explorer, expand the application Web.config file.

If any transform files have already been created, the Web.config file is displayed in Solution Explorer with a symbol indicating that it can be expanded, and the transform files are shown when you expand the Web.config file.

The build configuration that a transform is for is indicated by a string in the file name. For example, a transform file for the Debug build configuration is named Web.Debug.config.

If no transform file exists for the build configuration that you want to specify settings for, in Solution Explorer, right-click the Web.config file and then click Add Config Transforms.

Open the transform file for the build configuration that you want to work with.

Edit the transform file to specify the changes that should be made to the deployed Web.config file when you deploy by using that build configuration.

The default transform file includes comments that show how to code some common transforms.

More information on how to crate transforms is included in the following link:

https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations

0
9/25/2018 11:28:36 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow