connect to multiple sqlserver databases

Asked

Viewed 86 times

0

Good evening, I’m developing a system in MVC 5 and c#, I have two SQLSERVER database, one for Development and one for Production.

I ask to know how to configure Webconfig to accept these two connections and if and need to build some class that does this.

Clarifying:

When we develop the application we have a development web server that communicates with a development sqlserver database server, once this application is ready, it goes up to the production web server which should communicate with the Production SQLSERVER server.

What I need to do and configure webconfig for it to recognize which bank it should communicate in without having to change it manually as I have been doing.

  • Do you want to access the 2 connections at the same time?

  • Edit your question with details of what you’re trying to do, making it less broad and bring in the source code showing what you’re trying to do.

  • If one is development and another is production, you should not access them at the same time. Just change on the web.config when you need to switch between them.

1 answer

1

By default in the MVC project your web.config will already have two base transformation files: Web.Debug.config and Web.Release.Config. Both are already set to, when compiled, overwrite the main web.config with the desired information. So, if you publish your application in Release Mode your web.config will be with the connection string of Web.Release.config, and if you publish in debug, your web.config will be with the connection string with Web.Debug.config.

It is worth mentioning that you are not limited to only two transformation files, you can create still others according to your need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.