设为首页 加入收藏

TOP

C#批量附加指定目录下的所有数据库文件到数据库中(二)
2014-11-24 12:51:48 来源: 作者: 【 】 浏览:1
Tags:批量 附加 指定 目录 所有 数据库 文件
e(sb.ToString());
}
else if (System.IO.File.Exists(strLdfFilePath))
{
sb.Append(",@filename2='" + strLdfFilePath + "'");
AttachDataBase(sb.ToString());
}
else
{
Console.WriteLine("数据库文件" + strMdfFilePath + "缺少必备的日志文件!");
}
}
}
}
///
/// 连接数据库并执行附加对应的数据库文件命令
///

/// 附加数据库命令字符串
///
private bool AttachDataBase(string strSql)
{
SqlConnection con = new SqlConnection(@"Data Source=(local);Initial Catalog=master;Integrated Security=True");
try
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = strSql;
cmd.ExecuteNonQuery();
return true;
}
catch (Exception ex)
{
//如果数据库中存在名为要添加的数据库时则抛出异常
Console.WriteLine("附加数据库时异常:" + ex.Message);
return false;
}
finally
{
con.Close();
}
}


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Python中__init__.py文件的作用 下一篇MySQL源代码:为MySQL增加响应时间..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何利用Python做数 (2025-12-24 23:48:36)
·如何使用python进行 (2025-12-24 23:48:34)
·python 爬虫入门该怎 (2025-12-24 23:48:31)
·Java 实现多个大文件 (2025-12-24 23:22:00)
·Java多线程编程在工 (2025-12-24 23:21:56)