RobVious
RobVious

Reputation: 12925

Does deploying a .net web app always have to be so painful when dealing with multiple references to the connection string?

Deploying new versions of my web app is taking way too long. I know there's a better way to do this but I don't know what it is.

Right now I have three projects in a solution, all with their own web.config or app.config, each containing two connection strings.

In each web.config, there's the following:

sessionState mode="InProc" customProvider="DefaultSessionProvider">
  <providers>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="LocalConnection" />
  </providers>
</sessionState>

Note that it's set to LocalConnection now. If I publish up to Azure, I have to manually change this to "RemoteConnection". Every time.

I also have code like this in a few places throughout my app:

if (!WebSecurity.Initialized)
            WebSecurity.InitializeDatabaseConnection("LocalConnection",
                 "UserProfile", "UserId", "UserName", autoCreateTables: true);

This means that for each call like this, I have to manually change to "RemoteConnection" when I publish.

Also in my dbContext's empty constructor I call:

public AppDbContext()
        : base("name=LocalConnection")
    {

    }

Yet another manual update that needs to be done before publishing. Then all of these have to be reverted manually when I'm back to local testing.

What can I do to make this less tedious?

Upvotes: 2

Views: 114

Answers (1)

hidarikani
hidarikani

Reputation: 1131

How about Web.config transformations If you expand Web.config in Visual Studio you will see two more files: Web.Debug.config and Web.Release.config. You can add more configurations, for example Web.Staging.config.

Upvotes: 4

Related Questions