Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbscript doesnt work when imported to SSIS

Status
Not open for further replies.

SQLScholar

Programmer
Aug 21, 2002
2,127
GB
Hey all,

I have the below code:

Code:
Option Explicit Off
Option Strict Off

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime

Public Class ScriptMain

	' The execution engine calls this method when the task executes.
	' To access the object model, use the Dts object. Connections, variables, events,
	' and logging features are available as static members of the Dts class.
	' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
	' 
	' To open Code and Text Editor Help, press F1.
	' To open Object Browser, press Ctrl+Alt+J.

	Public Sub Main()
		'
		' Add your code here
        '

        StrConnect = "Driver={SQL Server};Server=(local);Database=audit;UID=sa;PWD=password"
        cnt = CreateObject("ADODB.Connection")
        cnt.Open(StrConnect)

        recordSet = CreateObject("ADODB.Recordset")
        SQLStr = "Select * from aduseroutput where lastlogontimestamp <> 0 and objectclass = 'user'"
        recordSet.Open(SQLStr, cnt, 1, 1)

        recordset.MoveFirst()
        x = 0
        Do Until recordset.EOF

            objUser = GetObject("LDAP://" & recordset.fields(0).Value)
            objLastLogon = objUser.Get("lastLogonTimestamp")
            objLastLogon = objLastLogon.HighPart * (2 ^ 32) + objLastLogon.LowPart
            objLastLogon = objLastLogon / (60 * 10000000)
            objLastLogon = objLastLogon / 1440
            objLastLogon = objLastLogon + #1/1/1601#

            cnt.Execute("Update aduseroutput set Convlastlogontimestamp = '" & CStr(objLastLogon) & "' where DN = '" & Recordset.fields(0).Value & "'")

            objUser = Nothing
            objLastLogon = Nothing
            Recordset.MoveNext()
        Loop


        recordset.Close()
        cnt.Close()
        recordset = Nothing
        cnt = Nothing



		Dts.TaskResult = Dts.Results.Success
	End Sub

End Class

I have used this code in vbs and it works perfectly. Then added it in sql SSIS script task. It has changed bits (i.e. removed SET) and now it doesnt work.

It doesnt like this line:

objLastLogon = objLastLogon + #1/1/1601#

adding a double to a date. How can i sort this out??

Dan

----------------------------------------
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Dr. Seuss

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
The Script Task uses VB.Net as the language, so you have to change your code to be compliant with VB.Net. If you want to keep the VBScript code as is, try using an ActiveX Script Task.
 
BE AWARE THAT THE ACTIVEX SCRIPT IS GOING AWAY. It is better to take the effort and rewrite the script.

DateAdd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top