Properties.Settings.Default 在发布模式下失败
在调试模式下,我一直在使用:
ConnectionString = Properties.Settings.Default.SomeConnectionString
检索我的连接字符串。但是,在发布模式下运行时,相同的代码不会给我连接字符串。
注意:SomeConnectionString 是本地 Settings.settings 文件中的连接字符串。
无论调试/发布模式如何,如何使用上面相同的代码?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用设置设计器设置连接字符串类型的设置,该设置将放置在 csproj 的 app.config 文件中。确保正确指定范围(应用程序或用户)。
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.
如果无法访问 web.config 中的连接字符串,则不应使用 Properties 文件来存储连接字符串,而应将连接字符串存储在 app.config 中。
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.