从数据库读取.NET配置 [英] Read .NET configuration from database

查看:106
本文介绍了从数据库读取.NET配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET 2.0及以上的配置系统是相当强大和可扩展的 - 只要你不想改变事实,它都来自文件系统中的XML文件。



在我的要求中,我无法更改文件,因为我的应用程序在受管环境中运行,但我可以更改SQL Server数据库。



我正在查看在SQL表中存储配置文件或部分 - 但如何将.NET 2.0配置系统绑定到此



是否有写一个自定义配置提供程序将读取其配置节不是从文件系统中的* .config文件,而是从SQL数据库中的表。



我一直在寻找创建自己的自定义ConfigurationSection或ConfigurationElement,或者甚至一个自定义配置本身 - 但似乎我总是回到这一点,我可以在文件系统中扩展配置系统尽可能多,我喜欢,但我不能让它从数据库表读取我的XML片段.....



我缺少什么?有人做了这个已经和关心解释/分享?



谢谢!
Marc



PS:我也试过将配置XML读入一个字符串,然后反序列化成适当的例子。 ServiceModelConfigSection - 不工作,不幸的是,因为ConfigSection基类不知何故没有实现它是必需的方法是XML可序列化........(YIKES !!!)

解决方案

这里有一篇文章谈论你在说什么:


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


总之,他们所做的是创建ProtectedConfigurationProvider的派生版本,通常用于加密.config文件。在解密方法中,不是解密配置信息,而是从数据库中检索。


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!!!)

解决方案

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.

这篇关于从数据库读取.NET配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆