Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
592 views
in Technique[技术] by (71.8m points)

sql server - Read .NET configuration from database

The .NET 2.0 and up configuration system is quite powerful and extensible - as long as you don't want to change the fact it all comes from XML files in the filesystem.

In my requirement, I cannot change files since my app runs in a managed environment outside my reach - but I could change the SQL Server database.

So I am looking at storing configuration files or sections in a SQL table - but how can I tie the .NET 2.0 configuration system into this??

Is there a way to write a "custom config provider" that will read its config sections not from a *.config file in the file system, but from a table in the SQL database??

I've been looking at creating my own custom ConfigurationSection or ConfigurationElement, or even a custom Configuration per se - but it seems I always end up back at the point that I can extend the config-system in the filesystem as much as I like, but I can't make it read my XML fragments from a database table.....

What am I missing? Has someone done this already and care to explain / share?

Thanks! Marc

PS: I also tried to just read the config XML into a string, and then deserializing it into the appropriate e.g. ServiceModelConfigSection - that doesn't work, unfortunately, because the ConfigSection base class somehow doesn't implement a method that is required for it to be XML serializable ........ (YIKES!!!)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There's an article here that talks about doing what you are talking about:

http://www.wrox.com/WileyCDA/Section/Redirecting-Configuration-with-a-Custom-Provider.id-291932.html

In summary what they do is create a derived version of ProtectedConfigurationProvider, which is typically used to encrypt .config files. In the Decrypt method, instead of decrypting the configuration information, it's retrieved from a database.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...