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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows authentication using vb script

Status
Not open for further replies.

williey

Technical User
Jan 21, 2004
242
Currently, I have a set of reports that are being refreshed using vb scripts. These set of reports go againsts Oracle DB where I pass the DB login information.

Code:
OPTION EXPLICIT

' Declare Constants
CONST DB_INSTANCE             = "TEST"
CONST DB_SERVER               = "TEST01"
CONST DB_USERID               = "Scott"
CONST DB_PASS                 = "tiger"
CONST INPUT_PATH              = "C:\Projects\Reports\"
CONST OUTPUT_PATH             = "C:\Projects\Reports\"
CONST FILE_EXT                = ".rpt"
CONST IN_FILE1                = "In_Report.rpt"
CONST OUT_FILE1               = "Out_Report"

CONST FIRST_DAY_OF_MONTH      = "01"

' Declare variables
Dim oRptApp, oRptSav, oRptChk, oRptSavParam1, oRptChkParam1
Dim oRptStat, oRptBrnch, oRptStatParam1, oRptBrnchParam1
Dim oRptMain, oRptRate, oRptMainParam1, oRptRateParam1
Dim oRptXfer, oRptBank, oRptXferParam1, oRptBankParam1 
Dim oRptPin, oRptPinParam1
Dim oRptCSMain, oRptCSAcct, oRptCSMainParam1, oRptCSAcctParam1

Dim strDate : strDate = Right(CStr(Year(Now)), 2) & Right("0" & CStr(Month(Now)), 2) & Right("0" & CStr(Day(DateAdd("d", -1, Now))), 2)
Dim startDate : startDate = Right("0" & CStr(Month(Now)), 2) & "/" & FIRST_DAY_OF_MONTH & "/" & CStr(Year(Now))
Dim endDate : endDate = Right("0" & CStr(Month(Now)), 2) & "/" & Right("0" & CStr(Day(DateAdd("d", -1, Now))), 2) & "/" & CStr(Year(Now))

' Check for Monthend
if Day(Now) = "1" then
  strDate = Right("0" & CStr(Year(DateAdd("y", -1, Now))), 2) & Right("0" & CStr(Month(DateAdd("m", -1, Now))), 2) & Right("0" & CStr(Day(DateAdd("d", -1, Now))), 2)
  startDate = Cstr( Right("0" & CStr(Month(DateAdd("m", -1, Now))), 2) & "/" & FIRST_DAY_OF_MONTH & "/" & Year(DateAdd("y", -1, Now)) )
  endDate = Cstr( Right("0" & CStr(Month(DateAdd("m", -1, Now))), 2) & "/" & Right("0" & CStr(Day(DateAdd("d", -1, Now))), 2) & "/" & Year(DateAdd("y", -1, Now)) )
end if

' Check for Yearend
if Day(Now) = "1" and Month(Now) = "1" then
  strDate = Right(CStr(Year(Now)), 2) & Right("0" & CStr(Month(DateAdd("m", -1, Now))), 2) & Right("0" & CStr(Day(DateAdd("d", -1, Now))), 2)
  startDate = Cstr( Right("0" & CStr(Month(DateAdd("m", -1, Now))), 2) & "/" & FIRST_DAY_OF_MONTH & "/" & Year(DateAdd("y", -1, Now)) )
  endDate = Cstr( Right("0" & CStr(Month(DateAdd("m", -1, Now))), 2) & "/" & Right("0" & CStr(Day(DateAdd("d", -1, Now))), 2) & "/" & Year(DateAdd("y", -1, Now)) )
end if

' Set the object for the App
Set oRptApp = CreateObject("CrystalRuntime.Application")



' ### Set the object for the Report
Set oRptChk = oRptApp.OpenReport(INPUT_PATH & IN_FILE1, 1)

' Set the authentication
oRptChk.Database.Tables.Item(1).SetLogOnInfo DB_SERVER, DB_INSTANCE, DB_USERID, DB_PASS

' Set the first parameter
Set oRptChkParam1 = oRptChk.ParameterFields.Item(1)

' Clear the first parameter value
oRptChkParam1.ClearCurrentValueAndRange

' Set the value of the first param
 oRptChkParam1.AddCurrentValue CDate(endDate)

oRptChk.ReadRecords

' Write to file to disk
oRptChk.SaveAs OUTPUT_PATH & OUT_FILE1 & "_" & "D" & strDate & FILE_EXT , 2048



' Set oRptParam = nothing
' Set oRpt = nothing
' Set oRptApp = nothing


Now I to automate the refreshing of another set of reports that uses Windows authentication. I tried commenting out the DB logon section. It generated the new report file but when I try to open in Crystal, I get "Failed to open document" and "Invalid version" error.

Has anyone used Windows authentication before? How does it work in vb scripts..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top