【问题标题】:Best way to retrieve the connection string for IBATIS.NET from the web.config从 web.config 检索 IBATIS.NET 连接字符串的最佳方法
【发布时间】:2010-09-28 06:47:22
【问题描述】:

我有一个 Web 应用程序,我需要在其中加密连接字符串并将其存储在 web.config 中。

检索此连接字符串并将此连接字符串与 IBATIS.NET 一起使用而不是将连接字符串存储在 SqlMap.config 中的最佳方法是什么?

【问题讨论】:

    标签: web-config ibatis.net


    【解决方案1】:

    this discussion thread 的最后三条消息讨论了你想要什么。

    本质上,您在调用 Configure() 之前覆盖了 iBATIS 从配置文件加载的连接字符串。

    例如,在您的 SqlMap.config 中:

    <database> <provider name="sqlServer2005" /> <dataSource name="TheDB" connectionString="${connectionString}"/> </database>

    在您配置构建器的代码中,类似于:

    DomSqlMapBuilder builder; string connection; NameValueCollection properties; connection = AccessTheEncryptedStringHere(); // Put the string in collection to pass to the iBATIS configurator properties = new NameValueCollection(); properties.Add("connectionString", connection); // Build the iBATIS configurator builder = new DomSqlMapBuilder(); builder.Properties = properties; builder.Configure("SqlMap.config");

    【讨论】:

    • 谢谢!即使使用谷歌,我也总是很难找到 iBATIS.NET 的信息
    • 我已经使用它 2 年了,只是偶然发现了一个我不知道的功能。邮件列表通常是最好的文档资源之一。其次是源本身。好的框架,但是是的,文档很少。祝你好运!
    • iBATIS.NET 在网络上几乎是一个秘密 ;-) 感谢您提供信息。
    • @Nicholas:我也是。现在我在 SO 上找到了这个问题,离完成我个人收集的 iBATIS.NET 技巧和窍门又近了一步。也许有一天我会分享它们:)
    【解决方案2】:

    你在寻找这个吗?从 web.config 中检索加密的连接字符串--

    您可以尝试以下方法。代码 - 连接字符串的名称是 omni_dbConnectionString

    string connectionString = ConfigurationManager.ConnectionStrings["myProtectedConfigProvider"].ProviderName;

    string connectionString = ConfigurationManager.ConnectionStrings["omni_dbConnectionString"].ConnectionString;

    【讨论】:

      猜你喜欢
      • 2016-12-11
      • 2011-08-18
      • 2016-08-13
      • 1970-01-01
      • 2010-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-10
      相关资源
      最近更新 更多