【问题标题】:app.config file in C# for SQL Server 2005 in VS 2008 [duplicate]VS 2008 中用于 SQL Server 2005 的 C# 中的 app.config 文件 [重复]
【发布时间】:2010-08-20 17:24:41
【问题描述】:

可能重复:
app.config file in C# for MS SQL Server 2005 in VS 2008

我有使用 Visual Studio 2008 编写的带有 SQL Server 2008 的 C# .net 项目。在那里我使用以下连接字符串连接 SQL Server:

string connectionString = @"server = HASIBPC\SQLEXPRESS; Integrated Security = SSPI; database = XPHotelManagementDatabase";

但问题是每次我将应用程序从一台计算机转移到另一台计算机时,我都需要更改“connectionString”中的“服务器”。我不想手动更改它。我希望这会动态变化。我将如何使用 app.config 做到这一点?

【问题讨论】:

  • 完全重复。出事了,怎么回事?
  • 实际上我的互联网连接已断开。而且我无法理解问题已提交。我再次提交了问题。我很抱歉我的错误。

标签: c# sql


【解决方案1】:

把它放在你的 app.config 中:

<configuration>
   <appSettings>
      <add key="server" value="HASIBPC\SQLEXPRESS" />
   <appSettings>
</configuration>

然后在您的代码中,使用以下命令访问它:

return ConfigurationSettings.AppSettings["server"].ToString();

【讨论】:

  • OP问了同样的问题here.
  • 对此我很抱歉。当我提交问题并再次提交此问题时,我的互联网连接断开了。
猜你喜欢
  • 1970-01-01
  • 2011-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多