Correct ConfigurationManager declaration when connecting to the database

How do I resolve the "ConfigurationManager not advertised" error message when used to connect to the database?

Here is the line of code that gives the error:

SQLConnStr= ConfigurationManager.ConnectionStrings("SQLConnStr").ConnectionString 
+4
source share
2 answers

You tried to add a link

  `System.Configuration` 

Help folder on you.

Just right-click the folder with your links in your project, then click the link. and then find System.Configuration, then ok.

then add

 Imports System.Configuration 

in your form

Change the application configuration 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 application configuration name and connection string name must be the same

add name = "SQLConnStr"

ConnectionStrings ("SQLConnStr").

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

and look at this:

Fix Name 'ConfigurationManager does not report an error

Hello

+7
source

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

0
source

Source: https://habr.com/ru/post/1348193/


All Articles