c#备份数据库

string SqlStr1="server=(local);database=''"+this.DropDownList.SelectedValue+'"';Uid=sa;Pwd=";

string SqlStr2="backup database"+this.DropDownList1.SelectedValue+"to disk='"+this.TextBox1.Text.Trim()+".bak";

SqlConnection con=new SqlConection(SqlStr1);

con.Open();

try

{

if(File.Exists(this.TextBox1.Text.Trim()))

{

Response.Write("");

return;

}

SqlCommand com=new SqlCommand(SqlStr2,con);

com.ExecuteNonQuery();

Response.Write("");

 

}

catch(Exception error)

{

Response.Write(error.Message);

Response.Write("");

finally

{

con.Close();

}

你可能感兴趣的:(c#)