【问题标题】:How to create connection string dynamically in C# [closed]如何在 C# 中动态创建连接字符串 [关闭]
【发布时间】:2013-05-12 19:32:36
【问题描述】:

如何在 C# 中动态创建连接字符串,而不是使用字符串连接创建?

【问题讨论】:

标签: c# winforms dynamic connection-string


【解决方案1】:

您可以使用 C# 中的 SqlConnectionStringBuilder 类创建动态连接字符串,如下所示。

更多详情请查看http://msdn.microsoft.com/en-us/library/dce36088.aspx

private void Form1_Load(object sender, EventArgs e)
{
     SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder();
     connectionString.DataSource = @".\SQLEXPRESS";
     connectionString.InitialCatalog = "MyDatabase";
     connectionString.IntegratedSecurity = true;
     MessageBox.Show(connectionString.ConnectionString);
}

【讨论】:

    【解决方案2】:

    你最好使用 ADO .NET 实体模型。请检查: Tutoriel ADO .NET

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-20
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 2014-06-13
      • 1970-01-01
      • 2013-08-15
      相关资源
      最近更新 更多