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
精彩评论