我有这个备份代码,我想每月执行一次,我熟悉在sql server management studio中使用作业或维护计划,但我想编写代码而不是使用sql server作业或维护计划。
的.aspx
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Add" CssClass="btn btn-success btn-lg" />
aspx.cs
protected void Button111_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ToString());
string backupDIR = "C:\backup";
if (!System.IO.Directory.Exists(backupDIR))
{
System.IO.Directory.CreateDirectory(backupDIR);
}
try
{
con.Open();
sqlcmd = new SqlCommand("backup database iporma to disk= '" + backupDIR + "\" + DateTime.Now.ToString("ddMMyy_HHss") + ".Bak'", con);
sqlcmd.ExecuteNonQuery();
con.Close();
lblError.Text = "Completed";
}
catch (Exception ex)
{
lblError.Text = "Error" + ex.ToString();
}
}
请放轻松我,我还是新手。
答案 0 :(得分:1)
创建Windows服务或Windows计划任务以执行此代码。您将在Google上找到有关如何创建Windows服务的好文章。
答案 1 :(得分:-2)
您的代码是正确的查询更改:您需要一个月然后您应该只使用MMM或mMm:
sqlcmd = new SqlCommand("backup database iporma to disk= '" + backupDIR + "\" + DateTime.Now.ToString("MMM") + ".Bak'", con);
答案 2 :(得分:-2)
include("connection.php");
if (isset($_POST['search'])) {
$valueToSearch= mysqli_real_escape_string($connect,$_POST['valueToSearch']);
$query="SELECT * FROM table_name WHERE Student_Name LIKE '%$valueToSearch%'";
$search_result=filterTable($query,$connect);
}
else{
$query="SELECT * FROM table_name";
$search_result=filterTable($query,$connect);
}
function filterTable($query,$connect)
{
$filter_Result=mysqli_query($connect,$query);
if (!$filter_Result) {
die('query is not valid '.mysqli_error($connect));
}
else{
return $filter_Result;
}
}