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:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection section = config.GetSection(sectionKey);
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.OpenAccessC ontextBase.GetScope()
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 http://stackoverflow.com/questions/7856951/unrecognized-attribute-configprotectionprovider-after-encrypting-app-config 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!