开发者

Correctly declaring ConfigurationManager when connecting to database

开发者 https://www.devze.com 2023-02-24 17:21 出处:网络
How do I solve the error message \"ConfigurationManager not declared\" when used to connect to database?

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

Here is the line of code which gives the error:

SQLCon开发者_开发百科nStr= ConfigurationManager.ConnectionStrings("SQLConnStr").ConnectionString


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.

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"

ConnectionStrings("SQLConnStr").

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

and have a look at this:

Fix the Name ‘ConfigurationManager’ is Not Declared Error

Regards


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

0

精彩评论

暂无评论...
验证码 换一张
取 消