OpenAccess failing with "Unrecognized attribute configProtectionProvider"

Thread is closed for posting
3 posts, 1 answers
  1. Felix
    Felix avatar
    5 posts
    Member since:
    Nov 2012

    Posted 03 Nov 2013 Link to this post



    I'm using VS 2012 Ultimate Update 3, Windows 7 Ultimate 64 bits, and OpenAccess Q3 2013. The data base is stored in MySQL 5.6.


    I've a solution with two projects:

    • A project containing the OpenAccess model
    • A project that's the main executable

    For security reasons, I'm encrypting my connection string stored in App.Config using code like the one that follows:

    public static void EncryptConfigSection(string sectionKey)
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ConfigurationSection section = config.GetSection(sectionKey);
            if (section != null)
                if (!section.SectionInformation.IsProtected)
                    if (!section.ElementInformation.IsLocked)
                        section.SectionInformation.ForceSave = true;


    However, there's a specific scenario where things go wrong:


    • Make an App.Config with no connection strings inside
    • Put code on main executable to add a connection string to App.Config and encrypt it (Method Connection)
    • Put code on main executable to do some data accesing with the OpenAccess model (Method Data)
    • Now, with the App.Config with no connection strings inside, run the main exe. This main exe first runs the Connection method and then the Data method


    The connection string being added in the Connection method has the same name of the connection expected by the OpenAcces model.

    What goes wrong is that the OpenAccess model is unable to get the recently encrypted string, the main executable has to be ran again with the connection string already encrypted in App.Config to avoid errors.


    It's the same exception that's explained in these sites:



    The stack trace of the ConfigurationErrorsException with message "Unrecognized attribute configProtectionProvider":

    en Telerik.OpenAccess.BackendConfiguration.GetConnectionStringByName(String name)
    en Telerik.OpenAccess.BackendC:onfiguration.Fix(Configuration& provider, String name)
    en Telerik.OpenAccess.DBRegistry.GetDatabase(String urlOrConnectionld, String cacheKey, Configuration& configuration)
    en Telerik.OpenAccess.Oatabase.Get(String connectionString, String cacheKey, BackendConfiguration backendConfiguration, MetadataContainer
    metadataContainer, OpenNotification onOpen, SchemaUpdateCallback schemaUpdateCallback)
    en Telerik.OpenAccess.OpenAccessContextBase.GetDatabase()
    en Telerik.OpenAccess.OpenAccessC ontextBase.GetScope()
    en Telerik.OpenAccess.OpenAccessContext.GetAllCore[T]()
    en Telerik.OpenAccess.OpenAccessContext.GetAll[T]()
    en OpenAccessTestModel.get_Categories()

    I've noticed that the very first method of the stack trace has the following as its first line of code:

    ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings[name];

    To bypass this issue I've tried initializing my OpenAccess model with the constructor that receives a connection string as a parameter, and I'm passing a full connection string (not an identifier that has to be resolved trough App.Config). However, using this constructor always gives the same exception, same stack trace, same Telerik.OpenAccess.BackendConfiguration.GetConnectionStringByName(String name) method being called, same ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings[name] giving troubles.

    I don't undestand why if I pass a full connection string the ConfigurationManager.ConnectionStrings is being called. It's a known NET trouble that if that static method is called it gives troubles when the encryption status of the ConnectionStrings has been changed in run time. Just want to avoid that method from being called. Last comment on points that using the non-static alternative works ok.

    Any posible solution to this trouble?

    Feel free to ask for more information if I missed something!

  2. Answer
    Ralph Waldenmaier
    Ralph Waldenmaier avatar
    202 posts

    Posted 05 Nov 2013 Link to this post

    Hi Felix,
    The described scenario is working with the code you provided.
    Attached you can find a small sample application that basically updates the database schema and reads some data. Initially, the connection string is not encrypted in the configuration file. After calling your method, it is encrypted. Creating a new Context with the connection alias was then successfully extracting the needed bits and I was able to connect to the database.

    In this example I was using the SampleCodeFirst NuGet package and changed the created Context to have a ctor that allows a connection string to be passed in. In my case it was the alias for the CS in the config.
    In order to get this project running, please restore the NuGet packages and adjust your connection string in the App.config file.

    I hope this example is useful for you.
    Do come back in case you need further assistance.

    Ralph Waldenmaier
    OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
  3. Felix
    Felix avatar
    5 posts
    Member since:
    Nov 2012

    Posted 05 Nov 2013 Link to this post

    Thanks for the example.

    I've now realized my trouble.

    I'm loading a secondary assembly with a different name than the main one. The secondary assembly is the one that has the code for working with the data base, the main assembly just encrypts connection strings. Obviously, the App.Config for the secondary assembly hasn't connection strings, and there my App fails.

    For solving my trouble I've removed any connection string from App.Config and pass the full connection string when initializing the OpenAccessContext. The only but is that now I've to make custom encryption routines, so, no ProtectSection() of ConfigurationManager.

    I'm truly sorry for any incovenience occasioned!
Back to Top