代码之家  ›  专栏  ›  技术社区  ›  Jon Cahill

从web.config中检索IBATIS.NET连接字符串的最佳方法

  •  3
  • Jon Cahill  · 技术社区  · 17 年前

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

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

    2 回复  |  直到 17 年前
        1
  •  4
  •   Nicholas Piasecki    17 年前

    最后三条消息 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");
    
    
        2
  •  0
  •   DOTNETexpert DOTNETexpert    17 年前

    你在找这个吗?从web.config检索加密的connectionstring--

    你可以试试foll。代码--

    string connectionString=ConfigurationManager.connectionString[“myProtectedConfigProvider”]。ProviderName;

    或

    推荐文章