110,535
社区成员
发帖
与我相关
我的任务
分享
foreach (DirectoryInfo tt in dir.GetDirectories("xuewei(*)*"))
{
string root_dir = tt.FullName;
string temp = tt.Name;
string table_dir = table_dir_root + temp;
string table_mdb_hb = table_mdb_hb_root + temp;
mdb_dir_info();
//释放SQL内存
sqlserver_restart(service);
for (int i = 20; i > 0; i--)
{
Thread.Sleep(1000);
this.Invoke(showlabeldelegate, new object[] { i });
}
private void mdb_dir_info()
{
using (SqlConnection pubconnection = new SqlConnection("Server=" + server + ";initial catalog=" + database_out + ";Integrated Security=SSPI"))
{
pubconnection.Open();
SqlCommand cmd = new SqlCommand("", pubconnection);
cmd.CommandTimeout = 5000;
cmd.CommandText = "if exists(select name from sys.objects where name ='" + table_dir + "' and type='u') begin drop table [" + table_dir + "] end"
cmd.ExecuteNonQuery();
cmd.Dispose();
pubconnection.Close();
}
}
private void sqlserver_restart(string service_name)
{
StreamWriter text = new StreamWriter("cmd.bat", false, Encoding.Default);
text.WriteLine("net "+"stop " + service);
text.WriteLine("net "+"start " + service);
text.WriteLine("");
text.Close();
Process.Start("cmd.bat");
}