Try Now
More in this section
Blogs RSS feed

How to use ‘web.config’ transformations with Sitefinity 4

by Gabe Sumner

Web.config transformations in Visual StudioASP.NET applications traditionally store database connection details in the web.config file.  Once configured, the entire web application can easily utilize these settings to connect to the database. 

However, Sitefinity 4 does not adhere to this traditional convention.  By default, Sitefinity stores database connection details in ~/App_Data/Sitefinity/Configurations/DataConfig.config.  This was done to support medium-trust environments.  In these environments, Sitefinity would not have access to modify the web.config file. However, circumventing the web.config makes it more difficult to manage different environments.

Development, Staging, Production…oh my!!!

During development it’s common to have different environments for various phases of the project.  Development might be done on a developer’s personal machine, testing on a staging server and then deployment onto a production server.  Each of these environments might utilize different application settings and different databases.

Visual Studio 2010 comes with a handy web.config transformation feature that makes it relatively painless to switch between these different configuration settings:

Switching to a different configuration in Visual Studio

However, this feature is not applicable to the DataConfig.config that Sitefinity uses by default.  Consequently, customers who are juggling different development & database environments with Sitefinity need to manually edit the DataConfig.config –OR- write a custom post build script.

Make Sitefinity use the web.config for the database connection string

Thankfully Sitefinity’s default behavior can be modified and traditional web.config database configurations utilized within Sitefinity.  To force Sitefinity to use the web.config’s database connectionstring, remove the connection string from the DataConfig.config and relocate it to the web.config.

1.  Remove the connectionString from the DataConfig.config

The connectionString section in Sitefinity's DataConfig.config

2.  And relocate it to the <configuration> section in the web.config

Moving Sitefinity's connectionStrings section to the web.config

That’s it!  Sitefinity will now use the web.config file for the database connectionString and Visual Studio 2010’s web.config transformation technique can now be used with Sitefinity.

More insights from Sitefinity’s Team…

The procedure outlined above is the easiest to follow & document.  However, while discussing this topic with the Sitefinity team, several other details and tactics began to emerge.

How does Sitefinity resolve conflicts between the web.config and the DataConfig.config?

“The connection strings from Web.config and DataConfig.config are merged and they all can be used by data providers. If there are connection strings with identical names in both configuration files the one form DataConfig.config is used.”

Unrecognized attribute 'dbType'. Note that attribute names are case-sensitive.

This is an error I received while following the instructions above.  To fix this error, I simply removed the dbType attribute from the web.config.  Here is what the team said about this error and my fix:

“In this case, the information which is specific for Sitefinity will be lost. For example, the dbType attribute specifies the Backend configuration, which will be used for OpenAccess mapping. By default it is MSSQL, so this approach could work correctly only for MS SQL. Since we support different databases now, we should probably improve this implementation.  For the time being in the blog post we can mention that this solution only works for MSSQL. However, in the future, if the connection string is in the web.config, we could try to get the information about the dbType from the connectionString attribute.”

Applying transformations to the DataConfig.config

Visual Studio’s transformation feature can also be applied to other files (not just the web.config).  This means that multiple DataConfig.config files could be maintained for different environments.  However, this feature requires that you hack your project.  A blog post, detailing this technique, can be found here.  A few of our Sitefinity projects, internally, are using this technique.

Parting words…

That’s it!  Hopefully this blog post will make it easier for anyone who is managing multiple environments for their Sitefinity project.  For more information about Web.config transformations, check out this great tutorial.


Leave a comment
  1. Mike May 26, 2011
    Great tip! We use Web.config transformations to support multiple environments for all our non-Sitefinity projects. It's nice to know we can do this for the Sitefinity connection string in the Sitefinity project rather than incurring the manual work and risk of maintaining separate DataConfig.config files for each environment.

  2. Jaap Coetzer Dec 08, 2011
    Thanks for the tip, this works great. But we picked up an issue when we changed from database A to B. We revoked access to A. But when we try to use the security manager through the API, it still tried to connect to A. I gave access back to A and ran sql profiler on A to try and see what is was doing but only got audit log in and log outs on the specific credentials, no queries at all otherwise...Otherwise all the data is pulled through from B and works fine... Any suggestions?
  3. Austin Dimmer Apr 11, 2012
    Hi Gabe,

    I am curious about what has happened with respect to the dbType attribute and support of other databases?

    I am currently trying to deploy on an Azure DB. I am uploading the project to Azure as I write this. Even it this does work against Azure, I imagine it may not be a supported configuration, and I will have concerns at the back of my mind that any issues I experience whilst running the project in Azure may be due to the fact that dbType is not specified and the DB against which the site is running is not the default MSSQL but SQLAzure.

    The reason why I wish to locate the connection string in web.config is that I am using config transforms to swap in an encrypted connection strings config for the production DB. I am mostly following the guidance at http://social.technet.microsoft.com/wiki/contents/articles/sql-azure-connection-security.aspx to achieve this.

    If the deployment does not work due to issues with the dbType attribute. Is there a supported way to encrypt sections of the Data.config files or other Sitefinity configuration files for that matter? (SMTP settings) This configuration encryption technique would have to support the custom encryption provider required by Azure and documented on the above link.

    If you find time I will be interested to hear your thoughts on this matter. I am coming to Beyond Sitefinity in London next week, so I hope to meet you there!
  4. Austin Dimmer Apr 11, 2012

    I suppose I have my answer!

    Wrong database backend configuration detected: Connecting to 'Microsoft SQL Azure (RTM) - 11.0.1855.1
    Mar 13 2012 11:34:31
    Copyright (c) Microsoft Corporation
    ' but configured for 'mssql'.

  5. Alex Sep 05, 2013
    You can also do transformation for dataconfig.config file. in fact it works fine for all configuraiton files in configuraiton folder.
    more about transforming dataconfig.config file there:

    Leave a comment