最近做了毕业设计,完成得差不多的时候就开始发布到IIS上面,连接数据库之类的都可以,但是在"数据备份"这一个功能出了些问题。数据库备份我是通过点击按钮来弹出一个保存对话框,然后执行备份,但是点击就会出错。并提示“您尝试在此 Web 服务器上访问的 Web 应用程序当前不可用。请点击 Web 浏览器中的“刷新”按钮重试您的请求。”
我在VS2010上可以备份的,为什么发布了就不行了呢?
具体代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
savefiledialog1 = new SaveFileDialog(); savefiledialog1.InitialDirectory = "e:/"; savefiledialog1.Filter = "bak files (*.bak)|*.bak"; invokethread = new Thread(new ThreadStart(invokemethod)); invokethread.SetApartmentState(ApartmentState.STA); invokethread.Start(); invokethread.Join(); if (result == DialogResult.OK)
{ if (savefiledialog1.FileName != "")
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString);
// conn.ConnectionString = "Data Source=LENOVO-1740B157\\SQLEXPRESS;Database=master;integrated security=true";
SqlCommand comm = new SqlCommand();
try
{
comm.Connection = conn;
comm.CommandText = "backup database bookorderingsystem to disk='" + savefiledialog1.FileName + "'";
// comm.CommandText = "data_resume";
// comm.CommandType = CommandType.StoredProcedure;
// comm.Parameters.Add("@s", SqlDbType.VarChar, 40);
// comm.Parameters["@s"].Value ="'"+ openfiledialog1.FileName+"'";
conn.Open();
comm.ExecuteNonQuery();
Response.Write("<script type='text/javascript'> alert('数据库备份成功!'); location='default.aspx'</script>"); }
catch
{
Response.Write("<script type='text/javascript'> alert('数据库备份失败!'); location='resume.aspx'</script>");
}
finally
{
conn.Close();
}
} }
}
我在VS2010上可以备份的,为什么发布了就不行了呢?
具体代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
savefiledialog1 = new SaveFileDialog(); savefiledialog1.InitialDirectory = "e:/"; savefiledialog1.Filter = "bak files (*.bak)|*.bak"; invokethread = new Thread(new ThreadStart(invokemethod)); invokethread.SetApartmentState(ApartmentState.STA); invokethread.Start(); invokethread.Join(); if (result == DialogResult.OK)
{ if (savefiledialog1.FileName != "")
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString);
// conn.ConnectionString = "Data Source=LENOVO-1740B157\\SQLEXPRESS;Database=master;integrated security=true";
SqlCommand comm = new SqlCommand();
try
{
comm.Connection = conn;
comm.CommandText = "backup database bookorderingsystem to disk='" + savefiledialog1.FileName + "'";
// comm.CommandText = "data_resume";
// comm.CommandType = CommandType.StoredProcedure;
// comm.Parameters.Add("@s", SqlDbType.VarChar, 40);
// comm.Parameters["@s"].Value ="'"+ openfiledialog1.FileName+"'";
conn.Open();
comm.ExecuteNonQuery();
Response.Write("<script type='text/javascript'> alert('数据库备份成功!'); location='default.aspx'</script>"); }
catch
{
Response.Write("<script type='text/javascript'> alert('数据库备份失败!'); location='resume.aspx'</script>");
}
finally
{
conn.Close();
}
} }
}
他提示应用程序不是以interactive模式运行时显示模式对话框或窗体是无效操作。请指定servicenotification或defaultdesktoponly样式,以显示服务应用程序发出的通知