Bao Cao Ve DTS

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

BAO CAO VE VIEC TM HIEU CHC NANG TONG HP SO LIEU CUA SQL SERVER

Qua trnh thc hien nhap, xuat va chuyen oi d lieu trong SQL Server c thc hien bi Data Transformation Services. Sau ay la mot so khai niem ma Data Transformation Services s dung en. 1. Package Data Transformation Services (DTS): DTS la bo cong cu cho phep nhap xuat d lieu gia cac he thong OLTP, ong thi DTS cung cho phep tong hp so lieu t he thong OLTP e xay dng Data Warehouse. Package la oi tng chnh cua DTS, ngha la DTS s dung khai niem package nh la mot n v d lieu cho qua trnh nhap, xuat va chuyen oi d lieu . Moi package nh ngha mot luong cong viec (Workflow), bao gom mot hay nhieu Task c thc hien thong qua nhng Step. Cac thanh phan cua mot package: Connection : nh ngha d lieu nguon/ch. Task: nh ngha hanh ong (xoa,truyen d lieu ....) se c thc hien trong package. Step : nh ngha th t thc hien cua cac Task. Co the tao Package t Enterprise Manager cua SQL Server, hay c tao bi mot ngon ng ho tr OLE Automation, v du nh Visual Basic. 2. Schedule Package Khi mot package a c lu, chung ta co the thc hien schedule e thi hanh (execute) package nay. Thi gian e thi hanh (run) mot package c schedule la tuy y : mot lan, moi ngay, moi tuan, moi thang, hay theo mot chu ky do chung ta quy nh. Chung ta cung co the sa oi thi gian thi hanh cua mot package thong qua SQLDMO t Custom Application. Trong SQL Server co hai cach e Schedule package: S dung Schedule Package option trong SQL Server Enterprise Manager. S dung SQL Server Agent Service. SQL Server Agent Service xem mot package a c schedule nh la mot oi tng Job. Mot Job trong SQL Server Agent tng ng nh la mot oi tng Job cua SQLDMO. Mot Job co the co mot hay nhieu Jobschedule, moi Jobschedule mo ta mot lch thc hien cua SQL Server Agent Job. ieu nay co ngha la Job co the co mot hay nhieu hn mot lch thi hanh va SQL Server Agent se t c lng tat ca cac lch nay e xac nh khi nao th thi hanh (run) Job nay. Tom lai, thong qua DTS package chung ta co the chuyen oi, tong hp d lieu t nhieu nguon d lieu khac nhau e xay dng Data warehouse. Sau khi tao DTS package chung

ta co the lap lch xac nh thi gian e cho package t ong thi hanh, ong thi chung ta cung co the sa oi thi gian thi hanh cua package thong qua Custom Appication bang oi tng SQLDMO trong ngon ng Visual Basic. SQL Distributed Management Objects (SQL-DMO) la mot tap cac oi tng tom gon cua s quan ly, ieu khien CSDL trong MS-SQL Server. Sau ay la mot so khai niem tng t trong viec Schedule package gia SQL Server Agent va SQLDMO. STT 1 2 3 Job Step SQL Server Agent SQL Server Agent Job Object JobStep Object SQLDMO JobServer Object

Vi JobServer Object chung ta co the: Start or stop SQL Server Agent on a server running SQL Server. Manage alerts, jobs, and operators. Enlist the server in a multiserver administration group
MOI LIEN HE GIA OI TNG JOBSERVER, JOB, JOBSCHEDULE, JOB STEP

3. Step Step objects coordinate the flow of control and execution of tasks in a DTS package. A task that does not have an associated object Step is never executed. Step objects

provide workflow capabilities to the package so that tasks are executed in a certain sequence. Co 3 loai rang buoc gia nhng Step: Loai Completion : Mot Step c thi hanh khi Step trc no a hoan thanh, ma khong can quan tam en Step trc no thanh cong hay b loi. Loai Success : Mot Step c thi hanh khi Step trc no a hoan thanh thanh cong, neu Step trc no b loi th no se khong thc hien. Loai Failure : Mot Step c thi hanh khi Step trc no b loi, neu Step trc no thanh cong th no se khong thc hien. Mot Step co the co nhieu rang buoc, khi o no ch c thc hien khi nao tat ca cac rang buoc eu c thoa man. Neu gia 2 Step khong co rang buoc nao th mac nh chung se c thc hien song song. V du minh hoa ve s thc hien cua cac Step

Success

Failure

Completion Trong v du tren StepA, StepB, StepC khong co rang buoc do o chung thc hien song song. StepD thc hien khi StepA thanh cong. Step E thc hien khi StepD b loi. Step F thc hien khi Step C hoan thanh. V du oan Code mo ta viec thc hien Schedule package va thi hanh cac package a c Schedule thong qua Application bang cach sng dung cac oi tng SQLDMO. 1. Hien th danh sach cac SQL Server Agent Job (cac package a c Schedule):
/*Khai bao Jobs Collection e lu cac SQL Server Agent Job */

Public OMyjobs As SQLDMO.Jobs


/*myser: Server can ket noi*/

Dim myser As SQLDMO.SQLServer Set myser = New SQLDMO.SQLServer myser.Connect "TDTHU", "sa", "" myser.JobServer.Start /*Start SQL Server Agent*/ Set OMyjobs = myser.JobServer.Jobs

For i = 1 To myser.JobServer.Jobs.Count lstJob.AddItem myser.JobServer.Jobs(i).Name /* Lay ten cua cac Job a vao ListBox*/
/* Jobs(i) la mot Job trong SQL Server Agent */

Next 2. Execute Job If (JobIndex <> -1) Then OMyjobs(JobIndex).Start /* Execute a Job a c chon trong Collection Jobs*/ MsgBox "Completed", vbCritical + vbOKOnly + vbExclamation Else MsgBox "No job selection", vbCritical + vbOKOnly End If 3. Modify JobSchedule: OMyjobs(JobIndex).JobSchedules(JobScheduleIndex).Schedule.BeginAlter /*Bat au thc
hien sa oi job , do mot job co the co nhieu JobSchedule nen ta phai chon JobScheduleIndex nao can sa oi*/

/*Cac thuoc tnh can sa*/ OMyjobs(JobIndex).JobSchedules(JobScheduleIndex).Schedule.FrequencyType FrequencyType /*sa thuoc tnh FrequencyType*/ =

OMyjobs(JobIndex).JobSchedules(JobScheduleIndex).Schedule.FrequencyRecurrenceF actor = FrequencyRecurrenceFactor OMyjobs(JobIndex).JobSchedules(JobScheduleIndex).Schedule. . . OMyjobs(JobIndex).JobSchedules(JobScheduleIndex).Schedule.DoAlter /*Ket thuc sa oi*/ OMyjobs(JobIndex).JobSchedules.Refresh 4. AddNew JobSchedule for Job: Dim NewJobSchedule As New SQLDMO.JobSchedule /*khai bao mot oi tng JobSchedule
mi */

Dim StartYear As String Dim StartMonth As String Dim StartDay As String NewJobSchedule.Name = txtNameJobSchedule /*Xac nh Ten cua Jobschedule*/ StartYear = DatePart("yyyy", Date)

StartMonth = DatePart("m", Date) StartDay = DatePart("d", Date) If Len(StartMonth) < 2 Then StartMonth = "0" & StartMonth If Len(StartDay) < 2 Then StartDay = "0" & StartDay
'========Gan gia tr cho cac thuoc tnh cua JobSchedule can tao =====

NewJobSchedule.Schedule.ActiveStartDate = StartYear & StartMonth & _ StartDay ' Schedule execution for once, each Sunday at 1:00 AM. NewJobSchedule.Schedule.ActiveStartTimeOfDay = "10000" NewJobSchedule.Schedule.FrequencyInterval = 1 NewJobSchedule.Schedule.FrequencyType = SQLDMOFreq_Daily NewJobSchedule.Schedule.FrequencyRecurrenceFactor = 0 ' Schedule never expires. NewJobSchedule.Schedule.ActiveEndDate = SQLDMO_NOENDDATE NewJobSchedule.Schedule.ActiveEndTimeOfDay = SQLDMO_NOENDTIME '==================================== OMyjobs(JobIndex).BeginAlter /*Bat au them mot Jobschedule mi cho mot Job*/ OMyjobs(JobIndex).JobSchedules.Add NewJobSchedule /*Them mot Jobschedule vao
Jobschedule Colecction cua job */

OMyjobs(JobIndex).DoAlter /*Ket thuc cong viec them*/ OMyjobs(JobIndex).JobSchedules.Refresh 5. Hien th danh sach cac JobSchedule cua mot Job: Dim nJobSchedule As Integer /* so lng JobSchedule cua mot Job*/ Dim i as integer txtJobName.Text = SchduleJob.OMyjobs(JobIndex).Name nJobSchedule = SchduleJob.OMyjobs(JobIndex).JobSchedules.Count /*em so lng
JobSchedule*/ /*a danh sach ten cua cac JobSchedule cua mot job a c xac nh thong qua JobIndex vao Listbox*/

For i = 1 To nJobSchedule lstSchedule.AddItem SchduleJob.OMyjobs(JobIndex).JobSchedules(i).Name Next i

You might also like