Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
; Winbatch 2004C ; Haven't Got a Connection String - create one visually ; ; This uses a non-exitent ini then sets a Connect String in it ; If the Cancel Button is pressed on the datalink dialog then ; a blank string is sent to the ini. Normally you would call ; the UDF if you were unsure of what providers existed on a PC ; or wanted to always visually create a Connection. ; NOTE: the UDF does not create a UDL, I uploaded a script to ; create a UDL a couple of years ago and it should be in ; the Tech Database. ; ; ; Stan Littlefield June 2, 2004 [please retain this header] ;/////////////////////////////////////////////////////////////////// #DefineFunction errDisplay() WbError = LastError() WbTextcode = WbError If WbError==1668||WbError==2669||WbError==3670 ; 1668 ; "Minor user-defined error" ; 2669 ; "Moderate user-defined error" ; 3670 ; "Severe user-defined error" WbError = ItemExtract(1,IntControl(34,-1,0,0,0),":") WbTextcode = -1 EndIf WbErrorString = IntControl(34,WbTextcode,0,0,0) WbErrorDateTime = StrCat(TimeYmdHms(),"|",StrFixLeft(GetTickCount()," ",10)) WbErrorFile = StrCat(DirWindows(0),"WWWBATCH.INI") IniWritePvt(WbErrorDateTime,"CurrentScript",WbErrorHandlerFile ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ErrorValue" ,WbError ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ErrorString" ,WbErrorString ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ScriptLine" ,WbErrorHandlerLine ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ScriptOffset" ,WbErrorHandlerOffset ,WbErrorFile) IniWritePvt(WbErrorDateTime,"VarAssignment",WbErrorHandlerAssignment,WbErrorFile) IniWritePvt("","","",WbErrorFile) WbErrorMsgText = StrCat(WbErrorDateTime,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"Current Script: ",WbErrorHandlerFile,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"LastError #:",WbError,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"Error Text: ",wberrortextstring,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"[Additional] ",wberroradditionalinfo,@CRLF,@CRLF) ; Line in script that caused Error. WbErrorMsgText = StrCat(WbErrorMsgText,"WbErrorHandlerLine:",@CRLF,WbErrorHandlerLine,@CRLF) ; Offset into script of error line, in bytes. WbErrorMsgText = StrCat(WbErrorMsgText,"WbErrorHandlerOffset: ",WbErrorHandlerOffset,@CRLF) ; Variable being assigned on error line, or "" if none. WbErrorMsgText = StrCat(WbErrorMsgText,"WbErrorHandlerAssignment: ",WbErrorHandlerAssignment,@CRLF) If (WbErrorHandlerAssignment>"") Then %WbErrorHandlerAssignment% = "UNKNOWN" ClipPut(WbErrorMsgText) WbErrorMsgText = StrCat(WbErrorMsgText,"[Error Copied To Clipboard]") Message("wbErrorHandler",WbErrorMsgText) Return("") #EndFunction #DefineFunction CreateConnect() oDataLink = 0 oCon = 0 c = "" oDataLink = CreateObject("DataLinks") oCon = CreateObject("ADODB.Connection") oDataLink.PromptEdit(oCon) c = oCon.ConnectionString oCon = 0 oDataLink = 0 Return(c) :WBERRORHANDLER IntControl(73,1,0,0,0) errDisplay() If oDataLink == 0 Then Return("ERROR:Data Links Not Supported") If oCon == 0 Then Return("ERROR:ADO Connection Not Created") #EndFunction ;//////////////////script begins//////////////////////////////////////////// IntControl(73,1,0,0,0) cStr = "" cINI = StrCat( FilePath(IntControl(1004,0,0,0,0)),"cString.ini") If ! FileExist( cINI ) str = StrCat("[Main]",@CRLF,"Connect=",@CRLF) FilePut( cINI,str ) Endif If IniReadPvt("Main","Connect","",cINI) == "" Then cStr = CreateConnect() If cStr<>"" || StrSub(cStr,1,5)<>"ERROR" IniWritePvt("Main","Connect",cStr,cINI) Else cStr = IniReadPvt("Main","Connect","",cINI) Endif Message("Connection String",cStr) ;then to test ;oCon = CreateObject("ADODB.Connection") ;oCon.Open( IniReadPvt("Main","Connect","",cINI) ) Exit :WBERRORHANDLER IntControl(73,1,0,0,0) errDisplay() Exit;////////////////////////////////////////////////////////////////////////////
Article ID: W16570
File Created: 2005:02:18:12:21:30
Last Updated: 2005:02:18:12:21:30