开发者

Properties.Settings.Default fails on Release Mode

开发者 https://www.devze.com 2023-01-28 23:17 出处:网络
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

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 o开发者_JAVA百科f debug/release mode?

Thanks!


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.


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消