.Net Windows 程序中的连接字符串

发布于 2024-11-29 13:43:12 字数 205 浏览 2 评论 0原文

我正在开发我的第一个 Windows .Net 应用程序(而不是我已经做过很多的 .net Web 应用程序),并且我有一个关于数据库连接字符串的问题 - 是否有与 web 中的部分等效的内容.config?

我希望能够针对我们的测试数据库运行该程序(这将需要不同的连接字符串。在 Windows .Net 应用程序中定义连接字符串对象的“规范”方法是什么?

谢谢

I'm working on my first Windows .Net application (as opposed to a .net web app, which I've done a lot of), and I have a question about database connection strings - is there an equivalent to the section in web.config?

I want to be able to have the program run against our test database (which will required a different connection string. What is the "canonical" way to define connection string objects in a Windows .Net application?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

银河中√捞星星 2024-12-06 13:43:12

与其再次把这一切写下来,这里有一篇关于这个主题的好文章:

存储和检索连接字符串

Rather than write this all down again, here's a good article on this subject:

Storing and Retrieving Connection Strings

盗心人 2024-12-06 13:43:12

将“应用程序配置”文件添加到您的项目中。它将添加一个名为“app.config”的文件,将您的连接放在那里。

编译应用程序时,它将更改配置文件的名称以匹配您的可执行文件。例如:MyApp.config。

我不确定定义连接字符串对象的“规范”方式是什么意思。随意命名它们。有时我们使用数据库的名称,有时仅使用项目的名称。

对于多个配置文件,我们使用配置转换。将它们命名为 app.config、app.debug.config、app.release.config 等,并使用配置管理器根据部署位置来定义要使用哪一个。

Add an "application configuration" file to your project. It will add a file called "app.config" Put your connection in there.

When the app is compiled it will change the name of the config file to match your executable. For example: MyApp.config.

I'm not sure what you mean by "canonical" way to define connection string objects. Name them whatever you want. Sometimes we use the name of the database, sometimes just the name of the project.

With regards to having multiple config files, we use Config Transforms. Which name them app.config, app.debug.config, app.release.config, etc. and use configuration manager to define which one to use based on where it's being deployed.

你怎么这么可爱啊 2024-12-06 13:43:12

非 ASP.Net 应用程序只需使用 app.config 而不是 web.config。请参阅此处

连接字符串可以作为键/值对存储在
配置元素的connectionStrings部分
应用程序配置文件。

Non ASP.Net apps simply use app.config instead of web.config. See here.

Connection strings can be stored as key/value pairs in the
connectionStrings section of the configuration element of an
application configuration file.

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