<connectionStrings>
<add name="System1.Properties.Settings.ConnectionString" connectionString="Data Source=PC-1\Instance1;Initial Catalog=System1;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
我在我的应用程序配置中有这个,然后在我的应用程序中使用它,如下所示:
ConnectionStringSettings myConnectionString = ConfigurationManager.ConnectionStrings["System1.Properties.Settings.ConnectionString"];
private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand mySqlCommand1 = new SqlCommand("someCommand")
{
mySqlCommand1.ExecuteNonQuery();
}}}
我也有备份数据库的功能
Server myServer = new Server(@"PC-1\Instance1");
Backup bkpDBFull = new Backup();
bkpDBFull.Action = BackupActionType.Database;
bkpDBFull.Database = "System1";
bkpDBFull.Devices.AddDevice(@"D:\Sample.bak", DeviceType.File);
bkpDBFull.BackupSetName = "Sample";
bkpDBFull.BackupSetDescription = "Sample";
bkpDBFull.ExpirationDate = DateTime.Today.AddDays(5);
bkpDBFull.Initialize = false;
bkpDBFull.SqlBackup(myServer);
我的问题是如何Server myServer = new Server(@"PC-1\Instance1")
在应用程序配置中添加它?