More in this section

Forums / Developing with Sitefinity / Configuring two ConnectionStrings

Configuring two ConnectionStrings

2 posts, 0 answered
  1. Bruno Michels
    Bruno Michels avatar
    125 posts
    16 Apr 2010
    15 Sep 2010
    Link to this post
    How can I set one connection string for "localhost" and one for "externalhost"?

    My default ConnectionString is set to "Sitefinity". I want to add a logic if (localhost) use "Sitefinity2".

    I don't know what I have to extend to change this behavior...
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    15 Sep 2010
    Link to this post
    Hello Bruno Michels,

    To summarize this, you want to change the connectionstring at runtime, but this is quite complex, because all data providers are closely connected to the connection you use.

    One of the option is changing the connection string as described in this post. Another option is using ConfigurationManager class

    // get access to dataAcess node 
    var c2 =(Telerik.DataAccess.Configuration.SectionHandler)ConfigurationManager.GetSection("telerik/dataAccess");
            // getting the first connection from dataAccess - you could loop through all
           var connectionStringName = c2.Connections[0].ConnectionStringName;
           var config = System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName];

    Sincerely yours,
    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
2 posts, 0 answered