1. Start Visual Studio 2005.

  2. From the File menu, select New Project. The New Project dialog box appears.

  3. In the Project Types pane, select Visual Basic. In the Templates pane, select Console Application.

  4. (Optional) In the Name box, type the name of the new application.

  5. Click OK to load the Visual Basic console application template.

  6. On the Project menu, select Add Reference item. The Add Reference dialog box appears. Select Browse and locate the SMO assemblies in the C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies folder. Select the following files:

    [引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETImports Microsoft.SqlServer.Management.SMO
    [引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET
    Imports Microsoft.SqlServer.Management.Common
    [引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET
    Imports Microsoft.SqlServer.Management.SMO.Agent
    [引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET

    On the View menu, click Code.-Or-Select the Form1.vb window to display the code window.

  7. In the code, before any declarations, type the following Imports statements to qualify the types in the SMO namespace:

     1[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Connect to the local, default instance of SQL Server.
     2[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETDim srv As Server
     3[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETsrv = New Server
     4[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Define an Operator object variable by supplying the Agent (parent JobServer object) and the name in the constructor.
     5[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETDim op As [Operator]
     6[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETop = New [Operator](srv.JobServer, "Test_Operator")
     7[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Set the Net send address.
     8[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETop.NetSendAddress = "Network1_PC"
     9[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Create the operator on the instance of SQL Server Agent.
    10[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETop.Create()
    11[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Define a Job object variable by supplying the Agent and the name arguments in the constructor and setting properties.
    12[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETDim jb As Job
    13[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjb = New Job(srv.JobServer, "Test_Job")
    14[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Specify which operator to inform and the completion action.
    15[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjb.OperatorToNetSend = "Test_Operator"
    16[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjb.NetSendLevel = CompletionAction.Always
    17[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Create the job on the instance of SQL Server Agent. 
    18[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjb.Create()
    19[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Define a JobStep object variable by supplying the parent job and name arguments in the constructor.
    20[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETDim jbstp As JobStep
    21[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbstp = New JobStep(jb, "Test_Job_Step")
    22[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbstp.Command = "Test_StoredProc"
    23[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbstp.OnSuccessAction = StepCompletionAction.QuitWithSuccess
    24[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbstp.OnFailAction = StepCompletionAction.QuitWithFailure
    25[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Create the job step on the instance of SQL Server Agent.
    26[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbstp.Create()
    27[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Define a JobSchedule object variable by supplying the parent job and name arguments in the constructor. 
    28[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETDim jbsch As JobSchedule
    29[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbsch = New JobSchedule(jb, "Test_Job_Schedule")
    30[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Set properties to define the schedule frequency and duration.
    31[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbsch.FrequencyTypes = FrequencyTypes.Daily
    32[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbsch.FrequencySubDayTypes = FrequencySubDayTypes.Minute
    33[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbsch.FrequencySubDayInterval = 30
    34[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETDim ts1 As TimeSpan
    35[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETts1 = New TimeSpan(900)
    36[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbsch.ActiveStartTimeOfDay = ts1
    37[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETDim ts2 As TimeSpan
    38[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETts2 = New TimeSpan(1700)
    39[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbsch.ActiveEndTimeOfDay = ts2
    40[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbsch.FrequencyInterval = 1
    41[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETDim d As Date
    42[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET= New Date(200311)
    43[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbsch.ActiveStartDate = d
    44[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NET'Create the job schedule on the instance of SQL Server Agent.
    45[引用]SQL Server 2005 Books Online  How to: Create a Job with Steps and a Schedule in Visual Basic .NETjbsch.Create()

     

相关文章:

  • 2021-12-08
  • 2022-12-23
  • 2022-02-03
  • 2021-11-11
  • 2021-07-01
  • 2022-03-05
  • 2022-12-23
  • 2022-01-04
猜你喜欢
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案