【发布时间】:2010-09-28 06:47:22
【问题描述】:
我有一个 Web 应用程序,我需要在其中加密连接字符串并将其存储在 web.config 中。
检索此连接字符串并将此连接字符串与 IBATIS.NET 一起使用而不是将连接字符串存储在 SqlMap.config 中的最佳方法是什么?
【问题讨论】:
标签: web-config ibatis.net
我有一个 Web 应用程序,我需要在其中加密连接字符串并将其存储在 web.config 中。
检索此连接字符串并将此连接字符串与 IBATIS.NET 一起使用而不是将连接字符串存储在 SqlMap.config 中的最佳方法是什么?
【问题讨论】:
标签: web-config ibatis.net
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");
【讨论】:
你在寻找这个吗?从 web.config 中检索加密的连接字符串--
您可以尝试以下方法。代码 - 连接字符串的名称是 omni_dbConnectionString
string connectionString = ConfigurationManager.ConnectionStrings["myProtectedConfigProvider"].ProviderName;
或
string connectionString = ConfigurationManager.ConnectionStrings["omni_dbConnectionString"].ConnectionString;
【讨论】: