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

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

问题描述

在.NET 2.0及以上系统的配置是相当强大的,可扩展的 - 只要你不想改变这一切都从XML文件在文件系统中的事实

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.

在我的要求,我不能改变的文件,因为我的应用程序在外面我手中有管理的环境中运行 - 但我可以改变SQL Server数据库

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.

所以,我期待在存储在SQL表的配置文件和部分 - 但我怎么能扎在.NET 2.0的配置系统到这个??

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??

有没有办法写一个自定义配置提供者,将读取其配置节未从文件系统中的* .config文件,但在SQL数据库中的表??

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??

我一直在寻求建立自己的自定义配置节或的ConfigurationElement,甚至是自定义的配置本身 - 但似乎我总是最后回到了一点,我可以扩展配置系统在文件系统中高达我很喜欢,但我不能让它从数据库表中读取我的XML片段......

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?

谢谢! 马克·

PS:我也试过,只是读取配置XML转换为字符串,然后反序列化到相应例如ServiceModelConfigSection - 不工作,遗憾的是,因为ConfigSection基类不知何故未实现所需的方法为它是XML序列化........(YIKES !!!)

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:

<一个href="http://www.wrox.com/WileyCDA/Section/Redirecting-Configuration-with-a-Custom-Provider.id-291932.html" rel="nofollow">http://www.wrox.com/WileyCDA/Section/Redirecting-Configuration-with-a-Custom-Provider.id-291932.html

在摘要他们做什么是创建ProtectedConfigurationProvider,其通常用来加密.config文件的派生版本。在该解密方法,代替解密的配置信息,它的检索从一个数据库中。

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天全站免登陆