Create a Data Link (.udl) during install
Posted 24 July 2001 - 22:45
TIA
Posted 25 July 2001 - 14:42
=====
function WriteUDL(szPath, szFile , szConnect)
NUMBERnvI;
NUMBERnvFileHandle;
STRINGszChar;
NUMBERnvDummy;
CHARchChar;
NUMBERnResult, nReturn;
STRINGsvResult;
begin
//delete file if it already exists
szChar = szPath ^ szFile;
DeleteFile (szChar);
// create UDL
OpenFileMode (FILE_MODE_BINARY);
CreateFile (nvFileHandle, szPath, szFile);
// write header
// #FF #FE
Sprintf(szChar, "%c", 0xFF);
WriteBytes (nvFileHandle, szChar, 0, 1);
Sprintf (szChar, "%c", 0xFE);
WriteBytes (nvFileHandle, szChar, 0, 1);
Sprintf (szChar, "%c", 0x00);
// write connectstring in UNICode
for nvI = 0 to StrLength(szConnect)
WriteBytes (nvFileHandle, szConnect, nvI, 1);
WriteBytes (nvFileHandle, szChar, 0, 1);
endfor;
Sprintf(szChar, "%c", 0x00);
WriteBytes (nvFileHandle, szChar, 0, 1);
Sprintf (szChar, "%c", 0x00);
WriteBytes (nvFileHandle, szChar, 0, 1);
CloseFile (nvFileHandle);
end;
=====
You can call it this way:
WriteUDL (sDIRudl, sFILEudl, "[oledb]\r
; Everything after this line is an OLE DB initstring\r
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sDIRmdb ^ sFILEmdb + ";Persist Security Info=False");
Posted 22 August 2001 - 20:10
OK, I'm trying to implement the code JWolters so kindly provided above. I have a CA which includes that function and an entry point function that calls it, passing the necessary filename and directory parameters. The problem is, the file is simply not created. I know the functions are both running, because I added a message box to each one so I could "see" in the install that they were actually running; and they are. However, after the install is complete, there is no udl file. I feel like there must be some small but obviously critical thing I am missing, but d&#%^ed if I can figure it out. I'll paste in the complete script of the CA below. Any help is greatly appreciated!
////////////////////////////////////////////////////////////////////////////////
//
// IIIIIII SSSSSS
// II SS InstallShield ®
// II SSSSSS © 1996-2000, InstallShield Software Corporation
// II SS All rights reserved.
// IIIIIII SSSSSS
//
//
// This template script provides the code necessary to build an entry-point
// function to be called in an InstallScript custom action.
//
//
// File Name: Setup.rul
//
// Description: InstallShield script
//
////////////////////////////////////////////////////////////////////////////////
// Include Isrt.h for built-in InstallScript function prototypes.
#include "isrt.h"
// Include Iswi.h for Windows Installer API function prototypes and constants,
// and to declare code for the OnBegin and OnEnd events.
#include "iswi.h"
// The keyword export identifies Call_WriteUDL() as an entry-point function.
// The argument it accepts must be a handle to the Installer database.
export prototype Call_WriteUDL(HWND);
prototype WriteUDL(STRING, STRING, STRING);
///////////////////////////////////////////////////////////////////////////////
//
// Function: Call_WriteUDL
//
// Purpose: This function will be called by the script engine when
// Windows Installer executes your custom action (see the "To
// Do," above).
//
///////////////////////////////////////////////////////////////////////////////
function Call_WriteUDL(hMSI)
// Declare local variables.
STRING sDIRudl;
STRING sFILEudl;
STRING sDIRmdb;
STRING sFILEmdb;
begin
// Script that will be executed when Call_WriteUDL is called.
sDIRudl = TARGETDIR ^ "\DataParc\database";
sFILEudl = "ctc_config.udl";
sDIRmdb = TARGETDIR ^ "\DataParc\database";
sFILEmdb = "ctc_config.mdb";
SprintfBox(INFORMATION, "Call_WriteUDL", "The entry point function is running");
WriteUDL (sDIRudl, sFILEudl, "[oledb]\r
; Everything after this line is an OLE DB initstring\r
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sDIRmdb ^ sFILEmdb + ";Persist Security Info=False");
end;
//////////////////////////////////////////////////////////////////////////////
//
// Function: WriteUDL
//
// Purpose: Creates a Microsoft Windows Data Link File (.udl)
// using the supplied filename and path info.
//
//////////////////////////////////////////////////////////////////////////////
function WriteUDL(szPath, szFile , szConnect)
NUMBER nvI;
NUMBER nvFileHandle;
STRING szChar;
NUMBER nvDummy;
CHAR chChar;
NUMBER nResult, nReturn;
STRING svResult;
begin
//delete file if it already exists
szChar = szPath ^ szFile;
DeleteFile (szChar);
// create UDL
OpenFileMode (FILE_MODE_BINARY);
CreateFile (nvFileHandle, szPath, szFile);
// write header
// #FF #FE
Sprintf (szChar, "%c", 0xFF);
WriteBytes (nvFileHandle, szChar, 0, 1);
Sprintf (szChar, "%c", 0xFE);
WriteBytes (nvFileHandle, szChar, 0, 1);
Sprintf (szChar, "%c", 0x00);
// write connectstring in UNICode
for nvI = 0 to StrLength(szConnect)
WriteBytes (nvFileHandle, szConnect, nvI, 1);
WriteBytes (nvFileHandle, szChar, 0, 1);
endfor;
Sprintf (szChar, "%c", 0x00);
WriteBytes (nvFileHandle, szChar, 0, 1);
Sprintf (szChar, "%c", 0x00);
WriteBytes (nvFileHandle, szChar, 0, 1);
CloseFile (nvFileHandle);
SprintfBox(INFORMATION, "WriteUDL", "The WriteUDL function is running");
end;
// To Do: Handle initialization code when each sequence (User Interface and
// Execute) starts.
// function OnBegin()
// begin
// end;
// To Do: Write clean-up code when each sequence (User Interface and Execute)
// ends.
// function OnEnd()
// begin
// end;
Posted 23 August 2001 - 00:45