Properties.Settings.Default 在发布模式下失败

发布于 2024-10-06 11:30:16 字数 272 浏览 0 评论 0原文

在调试模式下,我一直在使用:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

留蓝 2024-10-13 11:30:16

使用设置设计器设置连接字符串类型的设置,该设置将放置在 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.

好菇凉咱不稀罕他 2024-10-13 11:30:16

如果无法访问 web.config 中的连接字符串,则不应使用 Properties 文件来存储连接字符串,而应将连接字符串存储在 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文