If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Switching ADO data on the fly (Delphi on Interbase).

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-07-04, 16:00
AceOmega AceOmega is offline
Registered User
 
Join Date: Apr 2004
Location: Arizona
Posts: 49
Switching ADO data on the fly (Delphi on Interbase).

I came up with this nifty little program that will switch databases on the fly so that when I am running a patch, it will apply to the right data. Some of uor customers are using more than one database for their different locations so we needed a way to switch them.

The problem I ran into making this was setting the natural drive in reference to the sever sos that the database server can see the data from its point of view. The solution I came up with was to get the first letter of the volume name as the drive letter because most volume names are named by the drive letter.


Here is my code and my database system is (Firebird/Internet) using the XTG Systems ODBC Driver on the client...


procedure TPatchFrm.SwitchBtnClick(Sender: TObject);
Var
UNCPath : String;
begin

OpenDialog.FilterIndex := 2; {Sets to display Database Items}

if OpenDialog.Execute then { Display Open dialog box }
begin
if not FileExists(OpenDialog.FileName) then
begin
ShowMessage('Database '+OpenDialog.FileName+' does not exist');
Exit;
end;

{Extract Path from what the user has chosen}
UNCPath := ExpandUNCFileName(OpenDialog.FileName);
If Copy(UNCPath,0,2) = '\\' then
begin
UNCPath := Copy(UNCPath,3,Length(UNCPath));
HostName := Copy(UNCPath,0,POS('\',UNCPath)-1);{}
UNCPath := Copy(UNCPath,POS('\',UNCPath)+1,Length(UNCPath));
HostDrive := Copy(UNCPath,0,1)+':';{}
DBPath := Copy(UNCPath,2,Length(UNCPath));{}
end
Else
begin
HostName := 'LOCALHOST';
HostDrive := ExtractFileDrive(OpenDialog.FileName);
end;


{Set the ODBC driver to point to new path}
TRY
RegistryEdit := TRegistry.Create;
RegistryEdit.RootKey:= HKEY_LOCAL_MACHINE;
if RegistryEdit.OpenKey('\Software\ODBC\ODBC.INI\FBWo rd', False) then
begin
DataPath := RegistryEdit.ReadString('Database');
RegistryEdit.WriteString('Database',HostName+':'+H ostDrive+
DBPath);
DataPath := HostName+':'+HostDrive+ DBPath;
end
Else
begin
ShowMessage('The FBword ODBC driver is not installed.');
end;

{Reset the ADO connection}
ADOConnection1.Connected := False;
ADOConnection1.Connected := True;
ADOQuery1.Close;
ADOQuery1.Open;
DataSelected.Caption := ADOQuery1.FieldByName('NAME').AsString;

FINALLY {Clean Up}
RegistryEdit.CloseKey;
RegistryEdit.Free;
INHERITED;
END;

end;

End;


This workeds as long as the volume name is the drive letter on the server but I have a volume which is called "Public". If I set the path for the data on the client to "//MainServer/public/databases/clientx/data.gdb" it does not work because there is no volume "public" in reference to the server. If I switch out the public with "D:" which is the natural drive in reference to the sever, it works but I have no way of knowing what it is going to be on our customers server.

What I need is a way to make the server see voulme drives or to find out what the volumes natural drive letter is. Can any one help?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On