Is there something wrong with setting connection strings in applicationSettings?

.NET supports several ways to store configuration settings for quite some time, which has led to a lot of confusion. It doesn’t help that the three best hits for searching “Settings in C #” on MSDN are ten years (and many of the related questions [2] on this venerable site are also 6-7 years old). It is very difficult to determine which of the early recommendations was since outdated.

In my project, I decided to use ApplicationSettings(as opposed to AppSettings) because:

However, now I need to decide where to place the connection strings. The latest documentation on MSDN (and here, on SO , and also since CP ) still recommends using the section <connectionStrings> app.config. But accessing this from code requires the use of the old syntax, which I now consider deprecated with appSettings. In other words, it makes no sense to read one part of the file app.configwith the old syntax:

ConfigurationManager.ConnectionStrings["MydDBConnName"];

and another part of the same file with the new syntax :

Properties.Settings.Default.myOtherSetting;

Also, this prevents me from editing lines in the designer.

So bottom line: is there any reason not to standardize all my configuration settings (including connection strings) in an element ApplicationSettings?

+4
5

ConnectionStrings , , () DbConnection, DbCommand ..

, , , SQL, - ( , , , SQL) "" . .

(SQL Server, Oracle, ODBC, OleDB), ConnectionStrings .

+3

- -.

, DatabaseContext, , . ApplicationSettings.

(, ) , - Locator > .

, (, ), Root of Composition. , ApplicationSettings .

, / .

+2

, , <connectionStrings> , , . Windows , , , , , . .

, , , , " " . , <appSettings> , . , . , , , " ", - , .

+2

, ApplicationSettings . Entity Framework , ConnectionStrings. , , , . - Windows Authentication .

+1

The standard is what you do. For example, in my work environment, the only information that changes in a particular application is the server name. We have dev / test / prod servers. Therefore, we only save the SQL Server name in the configuration file. The database name does not change. We just read the database server from the configuration file and build the line in the application.

0
source

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


All Articles