function AttachDatabase(DatabaseName, userName, password: string): isc_db_handle;
var Buffer: array[0..1023] of char;
BufPtr: integer;
dbName: array[0..255] of char;
status: status_vector;
IBerrCode: isc_status;
dbHandle: isc_db_handle;
begin
StrPCopy(dbName, DatabaseName);
dbHandle := nil;
{init the Database Param buffer}
FillChar(Buffer, sizeof(Buffer), #0);
BufPtr := 0;
Buffer[0] := char(isc_dpb_version1);
inc(BufPtr);
Buffer[BufPtr] := char(isc_dpb_user_name);
inc(BufPtr);
Buffer[BufPtr] := char(length(username));
inc(BufPtr);
StrPCopy(@Buffer[BufPtr], username);
inc(BufPtr, length(username));
Buffer[BufPtr] := char(isc_dpb_password);
inc(BufPtr);
Buffer[BufPtr] := char(length(password));
inc(BufPtr);
StrPCopy(@Buffer[BufPtr], password);
inc(BufPtr, length(password));
{Attach Database Call }
try
IBerrCode := isc_attach_database(@status, 0, @DBName, @DBHandle, BufPtr, @Buffer);
except
if IBerrCode <> 0 then HandleIBErrors(@status);
end;
Result := dbHandle;
end;
|