vb.net 连接到数据库时正确声明 ConfigurationManager

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5671112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:27:00  来源:igfitidea点击:

Correctly declaring ConfigurationManager when connecting to database

vb.netconfigurationmanager

提问by sheron

How do I solve the error message "ConfigurationManager not declared" when used to connect to database?

用于连接数据库时出现“ConfigurationManager未声明”错误信息如何解决?

Here is the line of code which gives the error:

这是给出错误的代码行:

SQLConnStr= ConfigurationManager.ConnectionStrings("SQLConnStr").ConnectionString

回答by Crimsonland

Have you tried to Add Reference

您是否尝试过添加参考

  `System.Configuration` 

on you References Folder.

在您的参考文件夹中。

Just simply right click your references folder on your project then click add reference.. and then look for System.Configuration then ok.

只需右键单击项目上的引用文件夹,然后单击添加引用.. 然后查找 System.Configuration 然后确定。

then add

然后加

Imports System.Configuration 

on your form

在你的表格上

Change you app config to this:

将您的应用程序配置更改为:

<connectionStrings> 

<add name="SQLConnStr" connectionString="Data Source=HOTEL_MySQLSERVERR;Initial Catalog=GuestBooking;User ID=xyz;Password=xyz" providerName="System.Data.SqlClient" /> 

</connectionStrings>

//your app config name and connection string name must be the same

//您的应用配置名称和连接字符串名称必须相同

add name="SQLConnStr"

添加名称=“SQLConnStr”

ConnectionStrings("SQLConnStr").

连接字符串(“SQLConnStr”)。

SQLConnStr= ConfigurationManager.ConnectionStrings("SQLConnStr").ConnectionString

and have a look at this:

看看这个:

Fix the Name ‘ConfigurationManager' is Not Declared Error

修复名称“ConfigurationManager”未声明错误

Regards

问候

回答by Santosh wavare

I think you need to try removing and adding the reference again "System.Configuration.dll" Under Project > Add refrence > .Net > select System.Configuration

我认为您需要尝试删除并再次添加引用“System.Configuration.dll” 在 Project > Add refrence > .Net > 选择 System.Configuration