简体   繁体   中英

Properties.Settings.Default fails on Release Mode

In debug mode I have been using:

ConnectionString = Properties.Settings.Default.SomeConnectionString

to retrieve my connection string. However, this same code does not give me the connection string when running in release mode.

Note: SomeConnectionString is a connection string in a local Settings.settings file.

How can I use the same code above regardless of debug/release mode?

Thanks!

Instead of using a Properties file to store the connection string, you should store the connection string in app.config if you can't get access to the connection string in the web.config.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
     <connectionStrings>
        <add name="SomeConnectionString" 
        connectionString="Data Source=(local);Initial Catalog=Database;
        Persist Security Info=True;Integrated Security=SSPI;"                       
        providerName="System.Data.SqlClient" />
      <connectionStrings>
</configuration>

Use the settings designer to set a setting of type Connection String, which will be placed in the app.config file for your csproj. Make sure you specify the scope (Application or User) appropriately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM