Changing connection setting when deploying

8 posts, 0 answers
  1. Noam Berda
    Noam Berda avatar
    10 posts
    Member since:
    Mar 2007

    Posted 13 Oct 2011 Link to this post

    Hi,
    This is a basic question but i couldn't find the answer on the forum or the help site.

    I have a ORM model that i am developing on SQL Server 2008 R2 and the connection string is in the Web.Config. No problem with that.
    Then i have a Web.Deploy.Config that i am using when i am deploying my site to Azure. the deploy config alter the web.config and change the connection string for the azure. no problem with that as well.

    the problem is that i need to set somewhere (BackendConfiguration Backend=Azure) i assume that it need to be in the Web.Config and then i could change it via the deploy configuration. Were and how do i set the backend type on the web.config? Noam


     
  2. Noam Berda
    Noam Berda avatar
    10 posts
    Member since:
    Mar 2007

    Posted 14 Oct 2011 Link to this post

    Hi, Can someone help me on that please. How do I set up backend configuration in web.config when I am using a connection string? Noam
  3. DevCraft banner
  4. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 17 Oct 2011 Link to this post

    Hello Noam Berda,
    At the moment you have to add the logic. The easiest way is to use the app settings part in your web.config Just add a:
    <appSettings>
       <add key="OpenAccessBackend" value ="mssql"/>
       <!--add key="OpenAccessBackend" value ="azure"/-->
     </appSettings>

    to your web.config. Now you can use this setting in the static ctor of your generated context class. Please add a partial class and add code like this:

    using System.Configuration;
     
    namespace ConsoleApplication19
    {
        public partial class EntitiesModel
        {
            static EntitiesModel()
            {
                string backendString = "azure"; //fallback
                try
                {
                    string value = ConfigurationManager.AppSettings ["OpenAccessBackend"];
                    if (value != null)
                    {
                        backendString = value;
                    }
                }
                catch
                {
                    //todo: error reporting
                }
                backend.Backend = backendString;
            }
        }
    }


    Kind regards,
    Jan Blessenohl
    the Telerik team

    Check out the latest stable build of Telerik OpenAccess ORM. Download it and benefit from our new Project Templates.

  5. Noam Berda
    Noam Berda avatar
    10 posts
    Member since:
    Mar 2007

    Posted 17 Oct 2011 Link to this post

    Ok thanks, I will give it a try. I was expecting something like that. Noam
  6. Gary
    Gary avatar
    18 posts
    Member since:
    Jun 2012

    Posted 29 Jun 2012 Link to this post

    Is this still the recommended approach?  It seems like I have to modify the generated code to make the property backend protected instead of private to get this to work.

    Thanks,
    Gary
  7. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 02 Jul 2012 Link to this post

    Hello Noam,
    If you use Azure this is still the only way to do it, but you do not have to change the generated code.

    Please add a partial class to your generated context and override the OnDatabaseOpen method. Before calling the base class method you can now modify the passed in backend configuration object and set the right backend.

    Kind regards,
    Jan Blessenohl
    the Telerik team
    OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
  8. Gary
    Gary avatar
    18 posts
    Member since:
    Jun 2012

    Posted 03 Jul 2012 Link to this post

    Thanks Jan, that works.

    Gary

      For those interested, this is what I have now:

           
    protected string BackendString
    {
        get
        {
            string backendString = "azure";
            try
            {
                string value = ConfigurationManager.AppSettings["OpenAccessBackend"];
                if (value != null)
                    backendString = value;
            }
            catch { }
            return backendString;
        }
    }
     
    protected override void OnDatabaseOpen(BackendConfiguration backendConfiguration, Telerik.OpenAccess.Metadata.MetadataContainer metadataContainer)
    {
        base.OnDatabaseOpen(backendConfiguration, metadataContainer);
        backendConfiguration.Backend = BackendString;
    }
  9. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 05 Jul 2012 Link to this post

    Hi Noam,

    We have a new way to integrate settings from the app or web.config. You can now easily specify all backend configuration settings in the app.config file and use them by merging with the coded settings by calling

    BackendConfiguration.MergeBackendConfigurationFromConfigFile

    For more information, please have a look here.

    Sorry that I did not remember our new features.

    Regards,
    Jan Blessenohl
    the Telerik team
    OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
Back to Top
DevCraft banner