在c#应用程序中显示最后一次成功的SSIS作业的日期
本文关键字:SSIS 作业 日期 成功 最后一次 应用程序 显示 | 更新日期: 2023-09-27 18:16:43
我正在更新代码,以包括整个。aspx源代码,以便为那些帮助我输入代码的人提供更好的图片。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection maindb = new SqlConnection(My_Connection);
protected void Page_Load(object sender, EventArgs e)
{
String str = "Select Statement";
SqlCommand sc = new SqlCommand(str, maindb);
maindb.Open();
sc.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sc;
DataSet ds = new DataSet();
da.Fill(ds, "FirstName");
GridView1.DataSource = ds;
GridView1.DataBind();
maindb.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
String str = "Different Select Statement";
SqlCommand sc = new SqlCommand(str, maindb);
maindb.Open();
sc.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sc;
DataSet ds = new DataSet();
da.Fill(ds, "FirstName");
GridView1.DataSource = ds;
GridView1.DataBind();
maindb.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
我有一个每天运行的单步作业,它在SQL中更新一些表。
用我的c#基础知识,我创建了一个应用程序,在gridview中显示存储在SQL表中的数据。我想在应用程序上显示最后一次成功的作业运行日期,有点像"数据更新时间"之类的东西。
在其他堆栈溢出问题上,我发现这段代码显示了SQL管理工作室中最后一次成功的工作。
DECLARE @job_id binary(16)
SELECT @job_id = job_id FROM msdb.dbo.sysjobs WHERE (name = N'YourJobName')
SELECT TOP 1
CONVERT(DATETIME, RTRIM(run_date))
+ ((run_time / 10000 * 3600)
+ ((run_time % 10000) / 100 * 60)
+ (run_time % 10000) % 100) / (86399.9964) AS run_datetime
, *
FROM
msdb..sysjobhistory sjh
WHERE
sjh.step_id = 0
AND sjh.run_status = 1
AND sjh.job_id = @job_id
ORDER BY
run_datetime DESC
我的问题是如何在实际的应用程序中显示日期?
谢谢。
protected void Page_Load(object sender, EventArgs e)
{
String str = "Select Statement";
//Replace 'YourJobName' with the name of your SQL Job!
string sqlSelect = @"DECLARE @job_id binary(16)
SELECT @job_id = job_id FROM msdb.dbo.sysjobs WHERE (name = N'YourJobName')
SELECT TOP 1
CONVERT(DATETIME, RTRIM(run_date))
+ ((run_time / 10000 * 3600)
+ ((run_time % 10000) / 100 * 60)
+ (run_time % 10000) % 100) / (86399.9964) AS run_datetime
, *
FROM
msdb..sysjobhistory sjh
WHERE
sjh.step_id = 0
AND sjh.run_status = 1
AND sjh.job_id = @job_id
ORDER BY
run_datetime DESC";
using(var connection = new SqlConnection(My_Connection))
{
using (var sc = new SqlCommand(str, connection))
{
sc.ExecuteNonQuery();
using (SqlDataAdapter da = new SqlDataAdapter() { SelectCommand = sc })
{
DataSet ds = new DataSet();
da.Fill(ds, "FirstName");
GridView1.DataSource = ds;
}
GridView1.DataBind();
}
using (var adapter = new SqlDataAdapter(sqlSelect, connection))
{
var table = new DataTable();
adapter.Fill(table);
Label1.Text = Convert.ToString(table.Rows[0][0]);
}
}
}