+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Environment-Specific Sitefinity Connection Strings

Environment-Specific Sitefinity Connection Strings

9 posts, 0 answered
  1. John
    John avatar
    21 posts
    Registered:
    25 Nov 2008
    25 Feb 2009
    Link to this post
    Hi,

    I have a question regarding the Sitefinity connection string that is put into web.config in order to specify a server/database where the Sitefinity tables can live.  In particular, I wanted to ask about the possibility of making this connection string dynamic based on environment (i.e. development, test, staging, production).  I only need to change the server.  So if I have this in my web.config for development:

       <connectionStrings>  
            <add name="Sitefinity" connectionString="data source=devserver .........." />  
        </connectionStrings>  


    How can I change it to some other server if I know which environment I am in?  I do not want to go in and edit actual Sitefinity code, in an attempt to make upgrades as easy as possible.  Ideally, there would be a solution such as having multiple connection strings in the web.config, and I could specify at runtime (perhaps in my Application_Start method) which one Sitefinity will use.  For example:

        <connectionStrings> 
            <add name="SitefinityDev" connectionString="data source=devserver .........." /> 
            <add name="SitefinityTest" connectionString="data source=testserver .........." /> 
            <add name="SitefinityStaging" connectionString="data source=stagingserver .........." /> 
            <add name="SitefinityProd" connectionString="data source=prodserver .........." /> 
        </connectionStrings> 

    On each of the 4 servers, I have a database called "Sitefinity" which houses the Sitefinity tables, so that will be consistent.  I just need to be able to change server name at runtime.  Any thoughts?

    Thanks,
    John

  2. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    25 Feb 2009
    Link to this post
    Hey John,

    I personally don't know of an automatic method to accomplish this.  I did see the following section in the web.config file.

      <telerik> 
        <dataAccess defaultConnection="DefaultConnection"
          <connections> 
            <add name="DefaultConnection" driver="Nolics.ORMapper.DataProviders.SqlServer2005Provider" 
              connectionStringName="Sitefinity" /> 
            <add name="GenericContentConnection" driver="Telerik.Cms.Engine.Data.Providers.GCSql2005Provider, Telerik.Cms.Engine.Data" 
              connectionStringName="Sitefinity" /> 
          </connections> 
        </dataAccess> 
      </telerik> 

    Those 2 connectionStringNames can be pointed to something other than "Sitefinity" (for example "SitefinityTest").  I'm not sure if this is helpful or not.

    Gabe Sumner
  3. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    02 Mar 2009
    Link to this post
    Hi John,

    this is something ASP.NET developers have been wishing for quite a while and it's not really Sitefinity specific problem.  Here is a little background on the issue: connection string obviously cannot be stored in database, since it is needed for connection to be made. Keeping in anywhere else than in web.config would pose a security risk. Also, ConnectionStrings element is tightly incorporated in Visual Studio and many other third party controls, so it has became a convention to keep it there.

    Generally the way I personally handle this is to keep connection strings for all environments in the web.config, and I just comment out the ones I don't need. It's not pretty, but it works.

    I hope you'll find this information helpful. Let us know if there is anything else we can do for you.

    Regards,
    Ivan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. Tim
    Tim avatar
    2 posts
    Registered:
    10 Apr 2008
    15 Sep 2009
    Link to this post
    I too have been trying to work around this.  One of our clients has a QA and Production deployment system that requires the files on disk to be exactly the same, including the web.config file.  So unfortunately, commenting out the connection strings isn't an option.  Also, the application is not allowed to write to the file system, so we can't dynamically change the .config files.

    It would be very helpful to be able to override or create our own version of the config section handler so that we could put in our own logic to determine which connection string should be assigned to DefaultConnection.  Maybe being able to put this logic in the Telerik.DataAccess.Configuration.SectionHandler?  Does anything like that sound possible?

    Thanks,
    Tim
  5. Ravishankar Baranwal
    Ravishankar Baranwal avatar
    19 posts
    Registered:
    18 Mar 2009
    11 Oct 2010
    Link to this post
    I had deployed sitefinity in the development environment and now going to move at different server. This is taking the reference of old database how to change connection string. where i had already changed it in the web.config
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    11 Oct 2010
    Link to this post
    Hello Ravishankar,

    The only place where we set reference to the database is project's web.config file - <connectionStrings> section.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Ravishankar Baranwal
    Ravishankar Baranwal avatar
    19 posts
    Registered:
    18 Mar 2009
    12 Oct 2010
    Link to this post
    I had installed the sitefinity in devlopment environment and placed the connection string when deploying then also it is taking the previous connection string where as I had changes in the web.config. Please let me know why it is always caching the connection string given in first time.
    Also at the time of installation of sitefinity where this get stored. Please help me asap! thanks in advance
  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 Oct 2010
    Link to this post
    Hello Ravishankar Baranwal,

    There should be no caching in connection strings for the website. Editing the web.config will cause a restart of the website and therefore flush of all cache. Please check if you have some code where a connection string is hardcoded directly there and not pulled from web.config

    Regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Chris
    Chris avatar
    87 posts
    Registered:
    11 May 2010
    14 Oct 2010
    Link to this post
    In all of our web applications we have connection strings in an environment specific folder whose name matches the Solution Configuration in Visual Studio.

    e.g.

    /Configuration/Development/ConnectionStrings.config
    /Configuration/Staging/ConnectionStrings.config
    /Configuration/Production/ConnectionStrings.config

    We use a build event to copy the correct connection string (based on the Solution Configuration) into a folder called Current e.g. /Configuration/Current/ConnectionStrings.config, and reference this config file in our web.config so it is always environment specific.

    This is the build event, defined in our VS project:

    mkdir "$(ProjectDir)Configuration\Current"
    xcopy "$(ProjectDir)Configuration\$(ConfigurationName)" "$(ProjectDir)Configuration\Current" /E /Y

Register for webinar
9 posts, 0 answered