Use Windows.pkg Use cFilesystem\cFilesystem.pkg Use MSSqldrv.pkg Struct tsVDFServerConnection String sServer String sUid String sPwd String sDatabase Boolean bTrustedConnection End_Struct Object oMSSQLConnection_dg is a ModalPanel Set Size to 139 293 Set Label to "INT/Server connection" Set piMinSize to 89 211 Set Location to 2 2 Set Border_Style To Border_Thick Property tsVDFServerConnection plsConnection Property Boolean pbOk False Property String psINTFile "" Property tsSearchResult[] plsAllINTFiles Property String psAllIntFilesDir "" Object oFileSystem is a cFilesystem End_Object Object oOK_Btn is a Button Set Label to "&OK" Set Location to 121 184 Set peAnchors To anBottomRight Procedure OnClick Send LavNyConnectionInfo End_Procedure End_Object Object oCancel_Btn is a Button Set Label to "&Cancel" Set Location to 121 239 Set peAnchors to anBottomRight Procedure OnClick Send Stop_Modal_UI End_Procedure End_Object Object oServer is a Form Set Size to 13 187 Set Location to 11 83 Set Label to "Server:" Procedure Activating tsVDFServerConnection lsConnection Forward Send Activating Get plsConnection to lsConnection Set Value to lsConnection.sServer End_Procedure End_Object Object oUser is a Form Set Size to 13 100 Set Location to 28 83 Set Label to "User:" Procedure Activating tsVDFServerConnection lsConnection Forward Send Activating Get plsConnection to lsConnection Set Value to lsConnection.sUid End_Procedure End_Object Object oPassword is a Form Set Size to 13 100 Set Location to 45 83 Set Label to "Password:" Set Password_State to True Procedure Activating tsVDFServerConnection lsConnection Forward Send Activating Get plsConnection to lsConnection Set Value to lsConnection.sPwd End_Procedure End_Object Object oDatabase is a Form Set Size to 13 100 Set Location to 62 83 Set Label to "Database:" Procedure Activating tsVDFServerConnection lsConnection Forward Send Activating Get plsConnection to lsConnection Set Value to lsConnection.sDatabase End_Procedure End_Object Object oTrusted is a CheckBox Set Size to 10 50 Set Location to 79 83 Set Label to "Trusted connection." Procedure Activating tsVDFServerConnection lsConnection Forward Send Activating Get plsConnection to lsConnection Set Checked_State to lsConnection.bTrustedConnection End_Procedure Procedure OnChange tsVDFServerConnection lsConnection Forward Send OnChange Get plsConnection to lsConnection Get Checked_State to lsConnection.bTrustedConnection Set plsConnection to lsConnection Send RetEnabled End_Procedure End_Object Object oChangeAll is a CheckBox Set Size to 10 50 Set Location to 100 4 Set Label to "Change all x INT files i same directory." Procedure Activating tsSearchResult[] lsFiles Integer iSize String sAllIntFilesDir Forward Send Activating Set Checked_State to False Get plsAllINTFiles to lsFiles Get psAllIntFilesDir to sAllIntFilesDir Move (SizeOfArray(lsFiles)) to iSize If (iSize < 2) Begin Set Visible_State to False Set Enabled_State to False Set Label to "" End Else Begin Set Visible_State to True Set Enabled_State to True Set Label to (SFormat("Change all %1 INT files in %2.", iSize, sAllIntFilesDir)) End End_Procedure End_Object Object oTestConnection_bn is a Button Set Size to 14 67 Set Location to 121 4 Set Label to "&Test connection" Procedure OnClick Send TestConnection End_Procedure End_Object On_Key Key_Alt+Key_O Send KeyAction of oOK_Btn On_Key Key_Alt+Key_C Send KeyAction of oCancel_Btn On_Key Key_Alt+Key_T Send KeyAction of oTestConnection_bn Procedure RetEnabled tsVDFServerConnection lsConnection Get plsConnection to lsConnection Set Enabled_State of oUser to (not(lsConnection.bTrustedConnection)) Set Enabled_State of oPassword to (not(lsConnection.bTrustedConnection)) End_Procedure // Returs a VDF server connection string from a given tsVDFServerConnection struct. Function VDFServerConnectionStringFromStruct tsVDFServerConnection lsVDFServerConnection Returns String String sServer If (lsVDFServerConnection.bTrustedConnection) Begin Move (SFormat("SERVER_NAME SERVER=%1;TRUSTED_CONNECTION=YES;DATABASE=%2", lsVDFServerConnection.sServer, lsVDFServerConnection.sDatabase)) to sServer End Else Begin Move (SFormat("SERVER_NAME SERVER=%1;UID=%3;PWD=%4;DATABASE=%2", lsVDFServerConnection.sServer, lsVDFServerConnection.sDatabase, lsVDFServerConnection.sUid, lsVDFServerConnection.sPwd)) to sServer End Function_Return sServer End_Function // Gets the SQL server address from a given .INT file. // sINTFile has to be with full path. Function VDFServerConnectionStringFromINTFile String sINTFile Returns String String sServer sLine Integer iChannel Boolean bServer If (sINTFile <> "") Begin Get Seq_New_Channel to iChannel If (iChannel <> DF_SEQ_CHANNEL_NOT_AVAILABLE) Begin Direct_Input channel iChannel sINTFile Readln channel iChannel sLine While (not(SeqEof) and bServer = False) If (Pos("SERVER_NAME", (Uppercase(sLine))) > 0) Begin Move sLine to sServer Move True to bServer End Else Begin Readln channel iChannel sLine End Loop Close_Input channel iChannel Send Seq_Release_Channel iChannel End End Function_Return sServer End_Function Function ParseConnectionString String sConnectionString Returns tsVDFServerConnection tsVDFServerConnection lsVDFServerConnection String sConnectionItem String[] saConnection saConnectionValue Integer iNoOfConnectionItems iCurrentConnectionItem If (sConnectionString <> "") Begin If (Uppercase(Left(sConnectionString, 12)) = "SERVER_NAME ") Begin Move (Remove(sConnectionString, 1, 12)) to sConnectionString End Get Split sConnectionString ";" to saConnection Move (SizeOfArray(saConnection)) to iNoOfConnectionItems For iCurrentConnectionItem from 0 to (iNoOfConnectionItems -1) Get Split saConnection[iCurrentConnectionItem] "=" to saConnectionValue If (SizeOfArray(saConnectionValue) = 2) Begin Move (Trim(Uppercase(saConnectionValue[0]))) to saConnectionValue[0] Move (Rtrim(saConnectionValue[1])) to saConnectionValue[1] Case Begin Case (saConnectionValue[0] = "SERVER") Begin Move saConnectionValue[1] to lsVDFServerConnection.sServer Case Break End Case (saConnectionValue[0] = "UID") Begin Move saConnectionValue[1] to lsVDFServerConnection.sUid Case Break End Case (saConnectionValue[0] = "PWD") Begin Move saConnectionValue[1] to lsVDFServerConnection.sPwd Case Break End Case (saConnectionValue[0] = "DATABASE") Begin Move saConnectionValue[1] to lsVDFServerConnection.sDatabase End Case (saConnectionValue[0] = "TRUSTED_CONNECTION") Begin Move (Lowercase(saConnectionValue[1]) = "yes" or Lowercase(saConnectionValue[1]) = "true") to lsVDFServerConnection.bTrustedConnection Case Break End Case End End Loop End Function_Return lsVDFServerConnection End_Function Function Split String sVal String sChar Returns String[] String[] astVal String sHold Integer iCount While (Pos(sChar, sVal)>0) Move (Left(sVal, Pos(sChar, sVal)+Length(sChar)-1)) to sHold Move (Replace(sHold, sVal, "")) to sVal Move (Left(sHold, (Length(sHold)-Length(sChar)))) to astVal[iCount] Increment iCount Loop If (sVal<>"") Move sVal to astVal[iCount] Function_Return astVal End_Function Function NyConnectionStruct Returns tsVDFServerConnection tsVDFServerConnection lsConnection Get plsConnection to lsConnection Get Value of oServer to lsConnection.sServer Get Value of oDatabase to lsConnection.sDatabase Get Value of oUser to lsConnection.sUid Get Value of oPassword to lsConnection.sPwd Get Checked_State of oTrusted to lsConnection.bTrustedConnection Function_Return lsConnection End_Function Function NyConnectionString Returns String tsVDFServerConnection lsConnection String sServer Get NyConnectionStruct to lsConnection Get VDFServerConnectionStringFromStruct lsConnection to sServer Function_Return sServer End_Function Function HentINTFilen String sIntFil Returns String[] String[] saData String sLinie Integer iFilnr iAktLinie Boolean bEOF bOk bLukOk Get BinaryFileNextFilenumber of oFileSystem to iFilnr Get BinaryFileOpen of oFileSystem iFilnr sIntFil to bOk Move 0 to iAktLinie Repeat Get BinaryFileReadCachedLN of oFileSystem iFilnr (&sLinie) (&bEOF) to bOk If (bOk and not(bEOF)) Begin Move sLinie to saData[iAktLinie] Increment iAktLinie End Until (bOk = False or bEOF = True) Get BinaryFileClose of oFileSystem iFilnr to bLukOk Function_Return saData End_Function Function SkrivINTFilen String sIntFil String[] ByRef saData Returns Boolean Boolean bOk bLukOk Integer iFilnr iAntalLinier iAktLinie String sLinie BigInt biPos Get BinaryFileNextFilenumber of oFileSystem to iFilnr Get BinaryFileOpen of oFileSystem iFilnr sIntFil to bOk Set BinaryFilePosition of oFileSystem iFilnr to 0 Move 0 to iAktLinie Move (SizeOfArray(saData)) to iAntalLinier Repeat Move (saData[iAktLinie] + (Character(13)) + (Character(10))) to sLinie Get BinaryFileWrite of oFileSystem iFilnr (&sLinie) to bOk If (bOk) Begin Increment iAktLinie End Until (bOk = False or iAktLinie = iAntalLinier) Get BinaryFilePosition of oFileSystem iFilnr to biPos Set BinaryFileEndOfFile of oFileSystem iFilnr to biPos Get BinaryFileClose of oFileSystem iFilnr to bLukOk Function_Return bOk End_Function Procedure SkiftServerConnection String[] ByRef saData String sNyServerConnection Integer iAntalLinier iAktLinie Boolean bRettet Move (SizeOfArray(saData)) to iAntalLinier Move 0 to iAktLinie Move False to bRettet Repeat If (Uppercase(Left(saData[iAktLinie], 12)) = "SERVER_NAME ") Begin Move sNyServerConnection to saData[iAktLinie] Move True to bRettet End Else Begin Increment iAktLinie End Until (iAktLinie = iAntalLinier or bRettet = True) End_Procedure Function RetINTFiler String sServer Returns Boolean tsSearchResult[] lsINTFiler Integer iAntalFiler iAktFil Boolean bOk bChangeAll String[] saINTFilData String sAktINTFIl sIntDir Get Checked_State of oChangeAll to bChangeAll If (bChangeAll) Begin Get plsAllINTFiles to lsINTFiler Move (SizeOfArray(lsINTFiler)) to iAntalFiler End Else Begin Move 1 to iAntalFiler End Get psAllIntFilesDir to sIntDir Move True to bOk Move 0 to iAktFil Send Initialize_StatusPanel of ghoStatusPanel "Changing INT files" "VDF Server Connection String" "Changing connection string..." Send Start_StatusPanel of ghoStatusPanel Repeat If (bChangeAll) Begin Move (SFormat("%1\%2", sIntDir, lsINTFiler[iAktFil].sFilename)) to sAktINTFIl End Else Begin Get psINTFile to sAktINTFIl End Send Update_StatusPanel of ghoStatusPanel sAktINTFIl Get HentINTFilen sAktINTFIl to saINTFilData Send SkiftServerConnection (&saINTFilData) sServer Get SkrivINTFilen sAktINTFIl (&saINTFilData) to bOk Increment iAktFil Until (iAktFil = iAntalFiler or bOk = False) Send Stop_StatusPanel of ghoStatusPanel Function_Return bOk End_Function Procedure TestConnection tsVDFServerConnection lsConnection String sError sConnection Handle hSQLConnect Integer iResult Get NyConnectionStruct to lsConnection Get VDFServerConnectionStringFromStruct lsConnection to sConnection Move (Replace("SERVER_NAME ", sConnection, "")) to sConnection Get Create (RefClass(cSQLConnection)) to hSQLConnect Get SQLConnect of hSQLConnect MSSQLDRV_ID sConnection to iResult Send SQLDisconnect of hSQLConnect // Destroys the hSQLConnect object also. If (iResult <> 1) Begin Send UserError "Connection failed." "Connection test" End Else Begin Send Info_Box "Connection ok." "Connection test" End End_Procedure Procedure LavNyConnectionInfo String sServer Boolean bOk Get NyConnectionString to sServer Get RetINTFiler sServer to bOk Set pbOk to True Send Stop_Modal_UI End_Procedure Function ChangeConnectionInfo String sINTFilename Returns Boolean Boolean bOk tsVDFServerConnection lsConnection tsSearchResult[] lsResult Integer iAntalINT iAktINT String sConnectionString sTestINTFilename sIntFileDirectory Move False to bOk Set pbOk to bOk Move (Uppercase(sINTFilename)) to sTestINTFilename If (Right(sTestINTFilename, 4) <> ".INT") Begin Send UserError (SFormat("The file %1 is not an INT file.", sINTFilename)) Function_Return bOk End Get VDFServerConnectionStringFromINTFile sINTFilename to sConnectionString If (sConnectionString = "") Begin Send UserError (SFormat("Connection string was not found in INT file %1.", sINTFilename)) Function_Return bOk End Get ExtractFilePath sINTFilename to sIntFileDirectory If (Right(sIntFileDirectory, 1) = "\") Begin Move (Left(sIntFileDirectory, Length(sIntFileDirectory) - 1)) to sIntFileDirectory End Get FileSearch of oFileSystem (SFormat("%1\*.INT", sIntFileDirectory)) to lsResult Set plsAllINTFiles to lsResult Set psAllIntFilesDir to sIntFileDirectory Get ParseConnectionString sConnectionString to lsConnection Set plsConnection to lsConnection Set Label to sINTFilename Set psINTFile to sINTFilename Send Popup Get pbOk to bOk Function_Return bOk End_Function End_Object