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

发布于 2024-07-10 09:14:49 字数 129 浏览 4 评论 0原文

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

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

I have an web application where I have a requirement to encrypt and store the connection string in the web.config.

What is the best way to retrieve this and use this connection string with IBATIS.NET instead of storing the connection string in the SqlMap.config?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉墨 2024-07-17 09:14:50

此讨论主题的最后三条消息讨论你想要什么。

本质上,您在调用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");

The last three messages of this discussion thread discuss what you want.

Essentially, you're overwriting the connection string iBATIS loads from the config file before your call to Configure().

For example, in your SqlMap.config:


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

And in your code where you configure the builder, something like:


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");

眉目亦如画i 2024-07-17 09:14:50

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

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

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

字符串connectionString = ConfigurationManager.ConnectionStrings["omni_dbConnectionString"].ConnectionString;

Are you looking out for this? retrieving the encrypted connectionstring from web.config--

You can try the foll. code--
name of the connection string is omni_dbConnectionString

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

or

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文