VB.Net App.config访问 [英] VB.Net App.config access
本文介绍了VB.Net App.config访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好!
我看到了关于如何从app.config访问连接字符串的代码片段
hello!
I saw this code snippet on how to access the connection string from the app.config
Db.ConnectionString = ConfigurationManager.ConnectionStrings["con"].ToString();
我的问题是它对VB.Net无效...任何人都可以帮助我吗?
my problem is it does not work for VB.Net... can anyone help me?
推荐答案
嗨
也许你没有使用System.Configuration命名空间:
Hi
Maybe you did not using System.Configuration namespace :
<configuration>
<connectionstrings>
<add name="DBConnectionString">
connectionString="Data Source=Manoj;Initial Catalog=Test;Persist Security Info=True;User ID=sa;Password=admin123"
providerName="System.Data.SqlClient" />
</add></connectionstrings>
</configuration>
using System.Configuration;
string nwConn = System.Configuration.ConfigurationManager.ConnectionStrings[1].ToString();
但是你有很多不同的解决方案可以从app.config读取连接字符串,例如关注这些链接:
连接字符串App.Config
连接字符串和配置文件
连接字符串和应用程序配置
最好的问候。
However you have many different solutions for reading connection string from app.config for example follow of these links:
Connection string App.Config
Connection Strings and Configuration Files
connection string and app config
Best Regards.
Dim dbconn As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("con"))
<configuration>
<appsettings>
<add key="con" value="put your connection string here" />
</appsettings></configuration>
这篇关于VB.Net App.config访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文