Hi,
I am in the process of converting an ActiveX script to the new SSIS platform and I am looking for some ideas or prefer methods. I saw this posting tip and I am very interested in knowing if there are more examples. Currently, my ActiveX script performance several steps, it logs an audit record in the ELT_JOB_LOG table when the package is executed if the job id is not provided by the parent package. It also logs an audit record in the ETL_PROCESS_LOG table for the package. Most importantly, the ActiveX scripts ensures that the package variables are initialize with the values for downstream reference. Each package has the identical ActiveX script for logging auditing information.
Here is code from one of my ActiveX script which I am trying to migrate. I recently created a function that returns the next sequential process log id but I having difficult using it your sample code to execute. The purpose of using an Oracle function is to move the process to the database and just return the necessary values when called.
CREATE OR REPLACE FUNCTION SET_PROCESS_INFO_FUNC(FV_PROCESS_ID NUMBER,FV_JOB_ID NUMBER) RETURN VARCHAR2 IS
PRAGMA AUTONOMOUS_TRANSACTION;
LV_PROCESS_LOG_ID NUMBER; LV_JOB_ID NUMBER;
BEGIN
/*********************************************************************/ /** CHECK IF THE JOB ID WAS PROVIDED BY THE CALLING PROCESS (PARENT)**/ /** IF THE JOB ID WAS NOT PROVIDED THEN GENERATE/CREATE A NEW **/ /** JOB ID FOR THE PROCESS **/ /*********************************************************************/ IF FV_JOB_ID IS NULL THEN
SELECT NVL(MAX(LV_JOB_ID),0)+1 AS JOB_ID INTO LV_JOB_ID FROM ETL_JOB_LOG;
INSERT INTO ETL_JOB_LOG SELECT LV_JOB_ID, 'RUNNING' AS JOB_STATUS, FV_PROCESS_ID AS PROCESS_ID, TRUNC(SYSDATE) AS START_DT, TRUNC(SYSDATE) AS SYSTEM_DT, TO_CHAR(SYSDATE,'HH12:MI:SS AM') AS START_TIME, NULL AS END_TIME, DBMS_UTILITY.GET_TIME AS BTIME, NULL AS ETIME, NULL AS ELAPSED_TIME_SEC FROM DUAL;
COMMIT;
ELSE
LV_JOB_ID := FV_JOB_ID;
END IF;
/*********************************************************************/ /** CHECK IN SEE IF THE PROCESS IS ALREADY RUNNING **/ /** IF THE PROCESS IS ALREADY RUNNING LOG THIS JOB AS FAILED AND **/ /** RETURN THE PROCESS_LOG_ID TO THE CALLING PROCESS AS **/ /** VERIFICATION **/ /*********************************************************************/
SELECT PROCESS_LOG_ID INTO LV_PROCESS_LOG_ID FROM ETL_PROCESS_LOG WHERE PROCESS_STATUS = 'RUNNING' AND PROCESS_ID = FV_PROCESS_ID;
UPDATE ETL_JOB_LOG SET JOB_STATUS = 'FAILED', END_TIME = TO_CHAR(SYSDATE,'HH12:MI:SS AM'), ETIME = DBMS_UTILITY.GET_TIME, ELAPSED_TIME_SEC = (DBMS_UTILITY.GET_TIME-BTIME) / 100 WHERE LV_JOB_ID = LV_JOB_ID AND PROCESS_ID = FV_PROCESS_ID;
COMMIT;
RETURN TO_CHAR(LV_PROCESS_LOG_ID);
EXCEPTION WHEN NO_DATA_FOUND THEN
/*********************************************************************/ /** IF WE MADE IT THIS FAR, THE PROCESS IS NOT RUNNING AND WE CAN **/ /** LOG THE AUDIT RECORD IN THE ETL_PROCESS_LOG AUDIT TABLE **/ /*********************************************************************/
SELECT NVL(MAX(PROCESS_LOG_ID),0)+1 AS PROCESS_LOG_ID INTO LV_PROCESS_LOG_ID FROM ETL_PROCESS_LOG;
INSERT INTO ETL_PROCESS_LOG SELECT LV_PROCESS_LOG_ID, LV_JOB_ID, FV_PROCESS_ID, 'RUNNING' AS PROCESS_STATUS, TRUNC(SYSDATE) AS START_DT, TO_CHAR(SYSDATE,'HH12:MI:SS AM') AS START_TIME, NULL AS END_TIME, DBMS_UTILITY.GET_TIME AS BTIME, NULL AS ETIME, NULL AS ELAPSED_TIME_SEC FROM DUAL;
COMMIT;
/*********************************************************************/ /** UPDATE THE ETL_PROCESS_CONTROL TABLE WITH A START STATUS **/ /** FOR THE CURRENT PROCESS **/ /*********************************************************************/
UPDATE ETL_PROCESS_CONTROL SET STATUS = 'STARTED', LAST_UPDATED = SYSDATE WHERE PROCESS_ID = FV_PROCESS_ID;
COMMIT;
RETURN TO_CHAR(LV_PROCESS_LOG_ID);
END SET_PROCESS_INFO_FUNC; /
'********************************************************************** ' Visual Basic ActiveX Script '********************************************************************** ' Script Name..: xScriptTaskLogProcess.vbs ' DTS Package..: ' ' Comments.....: ' ' '***********************************************************************
'*********************************************************************** ' COMMAND TYPE ENUM VALUES '***********************************************************************
Const adCmdUnKnown = &H0008 Const adCmdText = &H0001 Const adCmdTable = &H0002 Const adCmdStoreProce = &H0004
Function Main()
Dim oConn, oRecordSet, oCmd Dim sSQL, iProcessLogID, iProcessID, sProcessStatus, iJobID, iCurrentJobID, sJobStatus Dim sEndTime, iETime, iElapsedTimeSec iProcessLogID = NULL '************************************************************** ' CREATE ADO OBJECTS '************************************************************** Set oConn = CreateObject("ADODB.Connection") Set oRecordSet = CreateObject("ADODB.Recordset") Set oCmd = CreateObject("ADODB.Command") '************************************************************** ' SET MSAORA CONNECTION PROPERTIES '************************************************************** oConn.Provider = "MSDAORA" oConn.Properties("Data Source").Value = DTSGlobalVariables("gsDataSource").Value oConn.Properties("User ID").Value = DTSGlobalVariables("gsUserID").Value oConn.Properties("Password").Value = DTSGlobalVariables("gsUserPassword").Value '************************************************************** ' THESE PROPERTIES ARE ONLY SET IF THE PROVIDER IS SQLOLEDB '************************************************************** 'oConn.Properties("Initial Catalog").Value = "" 'oConn.Properties("Integrated Security").Value = ""
'************************************************************** ' OPEN CONNECTIVITY TO THE DATABASE. '************************************************************** oConn.Open '************************************************************** ' SET THE ACTIVE CONNECTION TO THE TARGET DATABASE ADO OBJECT '************************************************************** oCmd.ActiveConnection = oConn oCmd.CommandType = adCmdText '************************************************************** ' PREPARE SQL STATEMENT FOR VERIFICATION OF RUN STATUS '************************************************************** sProcessStatus = "'" & "RUNNING" & "'"
sSQL = "SELECT PROCESS_LOG_ID, JOB_ID" &_ " FROM ETL_PROCESS_LOG" &_ " WHERE PROCESS_STATUS = " & sProcessStatus &_ " AND PROCESS_ID = " & CLng(DTSGlobalVariables("giProcessID").Value)
'************************************************************** ' EXECUTE THE SQL STATEMENT '************************************************************** oRecordSet.Open sSQL, oConn
'************************************************************** ' GENERATE NEW PROCESS LOG ID AND/OR JOB ID IF PROCESS IS NOT RUNNING '************************************************************** If Not(oRecordSet.EOF and oRecordSet.BOF) Then oRecordSet.MoveFirst iProcessLogID = oRecordSet.Fields("PROCESS_LOG_ID") End If oRecordSet.Close
'MsgBox "Process Log ID = " & iProcessLogID If IsNull(iProcessLogID) Then sSQL = "SELECT NVL(MAX(PROCESS_LOG_ID),0) AS IDVALUE" &_ " FROM ETL_PROCESS_LOG" 'MsgBox sSQL oRecordSet.Open sSQL, oConn If Not(oRecordSet.EOF and oRecordSet.BOF) Then oRecordSet.MoveFirst iProcessLogID = CLng(oRecordSet.Fields("IDVALUE")) + 1 'MsgBox "Process Log ID = " & iProcessLogID DTSGlobalVariables("giProcessLogID").Value = CLng(iProcessLogID) End If oRecordSet.Close '************************************************************** ' CHECK TO SEE IF JOB ID WAS PROVIDED BY THE CALLING PCKG ' IF NOT, GENERATE JOB ID FOR PROCESS AND LOG IT '************************************************************** If ( DTSGlobalVariables("giJobID").Value = 0 ) Then DTSGlobalVariables("giParentExecFlag").Value = False sSQL = "SELECT NVL(MAX(JOB_ID),0) AS IDVALUE" &_ " FROM ETL_JOB_LOG" oRecordSet.Open sSQL, oConn If Not(oRecordSet.EOF and oRecordSet.BOF) Then oRecordSet.MoveFirst iJobID = CLng(oRecordSet.Fields("IDVALUE")) + 1 DTSGlobalVariables("giJobID").Value = CLng(iJobID) End If oRecordSet.Close 'MsgBox "Job ID = " & iJobID oCmd.CommandText = "INSERT INTO ETL_JOB_LOG " &_ "SELECT " & DTSGlobalVariables("giJobID").Value & ", " &_ sProcessStatus & ", " &_ DTSGlobalVariables("giProcessID").Value & ", " &_ "SYSDATE" & ", " &_ "SYSDATE" & ", " &_ "TO_CHAR(SYSDATE,'HH12:MI:SS AM')" & ", " &_ "NULL" & ", " &_ "DBMS_UTILITY.GET_TIME" & ", " &_ "NULL" & ", " &_ "NULL" &_ " FROM DUAL" 'MsgBox oCmd.CommandText '************************************************************** ' EXECUTE AND COMMIT SQL STATEMENT '************************************************************** oCmd.Execute,,adExecuteNoRecords oCmd.CommandText = "Commit" oCmd.Execute,,adExecuteNoRecords Else DTSGlobalVariables("giParentExecFlag").Value = True
End If 'MsgBox "giParentExecFlag = " & DTSGlobalVariables("giParentExecFlag").Value oCmd.CommandText = "INSERT INTO ETL_PROCESS_LOG " &_ "SELECT " & DTSGlobalVariables("giProcessLogID").Value & ", " &_ DTSGlobalVariables("giJobID").Value & ", " &_ DTSGlobalVariables("giProcessID").Value & ", " &_ sProcessStatus & ", " &_ "SYSDATE" & ", " &_ "TO_CHAR(SYSDATE,'HH12:MI:SS AM')" & ", " &_ "NULL" & ", " &_ "DBMS_UTILITY.GET_TIME" & ", " &_ "NULL" & ", " &_ "NULL" &_ " FROM DUAL" 'MsgBox oCmd.CommandText '************************************************************** ' EXECUTE AND COMMIT SQL STATEMENT '************************************************************** oCmd.Execute,,adExecuteNoRecords oCmd.CommandText = "Commit" oCmd.Execute,,adExecuteNoRecords
'************************************************************** ' PREPARE SQL STATEMENT FOR UPDATING ETL_PROCESS_CONTROL TABLE '**************************************************************
sProcessStatus = "'" & "STARTED" & "'"
oCmd.CommandText = "UPDATE ETL_PROCESS_CONTROL " &_ " SET STATUS = " & sProcessStatus & "," &_ " LAST_UPDATED = SYSDATE " &_ " WHERE PROCESS_ID = " & CLng(DTSGlobalVariables("giProcessID").Value)
'MsgBox oCmd.CommandText
'************************************************************** ' EXECUTE AND COMMIT SQL STATEMENT '************************************************************** oCmd.Execute,,adExecuteNoRecords oCmd.CommandText = "Commit" oCmd.Execute,,adExecuteNoRecords
'************************************************************** ' CLOSE THE CONNECTION OBJECT '************************************************************** oConn.Close Main = DTSTaskExecResult_Success Else
'************************************************************** ' IF THERE IS AN EXISTING JOB RUNNING THIS ETL PROCESS OR ' DTS PACKAGE, THE FOLLOWING STATEMENT WILL UPDATE THE CURRENT ' STATUS OF THE JOB TO FAILURE '************************************************************** '************************************************************** ' PREPARE AND EXECUTE SQL STATEMENT TO OBTAIN EXECUTION TIME '**************************************************************
sSQL = "SELECT BTIME, " &_ " TO_CHAR(SYSDATE,'HH12:MI:SS AM') AS END_TIME, " &_ " DBMS_UTILITY.GET_TIME AS ETIME, " &_ " (DBMS_UTILITY.GET_TIME - BTIME)/100 AS ELAPSED_TIME_SEC " &_ " FROM ETL_JOB_LOG " &_ " WHERE JOB_ID = " & CLng(DTSGlobalVariables("giJobID").Value) &_ " AND PROCESS_ID = " & CLng(DTSGlobalVariables("giProcessID").Value)
'msgbox sSQL
oRecordSet.Open sSQL, oConn
'************************************************************** ' RETRIEVE RECORD FIELD VALUE FOR ETIME AND ELAPSED_TIME_SEC '************************************************************** If Not(oRecordSet.EOF and oRecordSet.BOF) Then
oRecordSet.MoveFirst sEndTime = oRecordSet.Fields("END_TIME") iETime = oRecordSet.Fields("ETIME") iElapsedTimeSec = oRecordSet.Fields("ELAPSED_TIME_SEC")
End If
'************************************************************** ' CLOSE THE RECORD SET OBJECT '************************************************************** oRecordSet.Close '************************************************************** ' UPDATE JOB AUDIT STATUS '************************************************************** sJobStatus = "'" & "FAILED" & "'" sEndTime = "'" & sEndTime & "'"
oCmd.CommandText = "UPDATE ETL_JOB_LOG " &_ " SET JOB_STATUS = " & sJobStatus & "," &_ " END_TIME = " & sEndTime & "," &_ " ETIME = " & CLng(iETime) & "," &_ " ELAPSED_TIME_SEC = " & CLng(iElapsedTimeSec) &_ " WHERE JOB_ID = " & CLng(DTSGlobalVariables("giJobID").Value) &_ " AND PROCESS_ID = " & CLng(DTSGlobalVariables("giProcessID").Value)
'MsgBox oCmd.CommandText
'************************************************************** ' EXECUTE AND COMMIT SQL STATEMENT '************************************************************** oCmd.Execute,,adExecuteNoRecords oCmd.CommandText = "Commit" oCmd.Execute,,adExecuteNoRecords
'************************************************************** ' CLOSE THE CONNECTION OBJECT '************************************************************** oConn.Close Main = DTSTaskExecResult_Failure End If
End Function
|