[英]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. 注意:SomeConnectionString是本地Settings.settings文件中的连接字符串。
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. 如果无法访问web.config中的连接字符串,则应将连接字符串存储在app.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. 使用设置设计器来设置连接字符串类型的设置,该设置将放置在csproj的app.config文件中。 Make sure you specify the scope (Application or User) appropriately.
确保适当地指定范围(应用程序或用户)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.