WebService does not read web.config

I have 3 connectionstrings in web.config and I used them like this:

using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SomeName"].ConnectionString))

Each metgod is called by the winforms application.

One of the web methods does not work properly, because it reads only one String connection:

data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true

This is not the connectionString from my web.config.

I call each method in the same way.

How is this impossible?

Edition:

I use the facade: This is the structure: WinForms calls WebMethod SaveItem Method to call SaveItem on the Facade: SaveItemAndDoDatabaseStuff SaveItemAndDoDatabaseStuff makes the database.

+3
source share
5 answers

-, , IIS, web.config? ...

IIS , ( cog).

+4

asp.net( machine.config .net).

:

<configuration>
  <connectionStrings>
    <clear/>
    ... your connection strings here
  </connectionStrings>
</configuration>

Btw, , "SomeName" . , : "LocalSqlServer".

+1

web.config app.config , .

app.config winforms.

0

WinForms X ( -), X app.config( WinForms).

- ( , ), X, Y Z, X, Y Z web.config( -).

0

, . :

        System.Diagnostics.Trace.WriteLine(
            System.AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
            "APP_CONFIG");

Set a breakpoint after this and see the output window for the line that starts with "APP_CONFIG:". This will give the full path to the configuration file and allow you to determine where it is downloaded. If you still see a mismatch between the run-time values ​​and the configuration file, something will probably change these values ​​at run time in your application.

0
source

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


All Articles