0

I am a rookie with ASP.NET currently developing monitoring system for SQL Server, and still working on retrieving job's information so I can show them on the page.

I tried to use Mr. Alexey Zimarev's code this code

And I wrote it on my controller like this

public class JobsController : Controller
{
    static readonly string SqlServer = @"DESKTOP-PQD9KKN";

    private ApplicationDbContext _context;

    public JobsController()
    {
        _context = new ApplicationDbContext();
    }

    protected override void Dispose(bool disposing)
    {
        _context.Dispose();
    }

    [Route("Customers/MigrateJob")]
    public ActionResult MigrateJob()
    {
        ServerConnection conn = new ServerConnection(SqlServer);
        Server server = new Server(conn);
        JobCollection jobs = server.JobServer.Jobs;

        foreach(Job job in jobs)
        {
            var jobactivity = new JobActivity
            {
                Name = job.Name,
                IsEnabled = job.IsEnabled
                ....so on
            };
            _context.JobActivities.Add(jobactivity);
        }
        return RedirectToAction("List", "Jobs");
    }

    public ActionResult List()
    {
        var jobactivities = _context.JobActivities.ToList();

        return View(jobactivities);
    }
}

My approach is to store the job's information from SQL Server Agent to my JobActivity table using MigrateJob(). The problem is the job's information hasn't stored in my table yet without any error messages.

My Tools:

  • VS 2017
  • SQL Server ver 13

Any help would be appreciated :)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

0 Answers0