Subject | RE: [ib-support] All about different connection strings? Working version |
---|---|
Author | Alan J Davies |
Post date | 2002-11-07T14:33:08Z |
I have more light to cast :-) on this subject. Finally (for me) I can
happily connect via an IP address. So thanks to all concerned. Let me just
give my example of what to do. Those who already know can grab a coffee
now.
If, like me, you use parameters in Delphi to retain various settings then
this is of interest.
This is a real-life example so insert your own filepaths etc.
Set the HOSTS file on the client machine (located in
\winnt\system32\drivers\etc\ or \windows\ on 98)
In the HOSTS file you can have a number of different hostnames pointing
to the same IP address - so you can have e.g.
192.168.0.15 fibroserver # Name used for the IP test application
192.168.0.15 aldis-server # Real name for server for other use
I use 2 string variables for clarity. App_Name, App_Path. One of the thread
responses indicated that IP addressing may create an error if it encounters
'\' so this simple loop changes each '\' to '/'
App_Path:=ExtractFilePath(Application.ExeName); // result
c:/apps/fibrosys/thetford/
App_Name:='fibroserver:';
for n:=1 to length(App_Path) do
begin
if copy(App_Path,n,1)='\' then
App_Name:=App_Name+'/'
else
App_Name:=App_Name+copy(App_Path,n,1);
end;
// result fibroserver:c:/apps/fibrosys/thetford
IBDatabase1.DatabaseName:=App_Name+'Fibrosys.gdb'; // this will not work
.... open database etc....
This correctly opens fibroserver:c:/apps/fibrosys/thetford/Fibrosys.gdb on
the server. BUT it will fail with SQL error -901 on the client. The reason
is that there must be some TCP layer error which I have not resolved yet.
The following works - the string is exactly the same as the version above
when expanded. So the answer is to hard-code the location by the look of
things.
IBDatabase1.DatabaseName:=fibroserver:c:/apps/fibrosys/thetford/Fibrosys.gd
b;
On the client, both versions translate into
fibroserver://aldis_server/apps/fibrosys/thetford/Fibrosys.gdb
I hope this sorts out a few problems - it took quite a while for me to
resolve
ps - I have since put the location into a txt file and use a
listbox.loadfromfile to get the correct settings - make this a read-only
file if you use this idea. My final version is now going into all
applications where there is a possibility nof remote access or access from
a different IP segment
// Location of DataBase using settings in App_Data.Txt in App Folder
*********
// App_Data.Txt should be read-only, possibly hidden - allows for moving
to any
// Folder BUT needs to be exactly as per Folder location
App_Path:=ExtractFilePath(Application.ExeName);
Form1.App_PathBox.Items.Clear;
Form1.App_PathBox.Items.LoadFromFile(App_Path+'App_Data.Txt');
App_Name:=Form1.App_PathBox.Items[0];
Form1.App_PathBox.Items[0]:='IP='+App_Name;
Form1.App_PathBox.Items[1]:='DS='+App_Path;
if IBDatabase1.Connected=True then
IBDatabase1.Connected:=False;
IBDatabase1.DatabaseName:=App_Name;
IBDatabase1.Connected:=True;
Alan J Davies
email: alan@...
happily connect via an IP address. So thanks to all concerned. Let me just
give my example of what to do. Those who already know can grab a coffee
now.
If, like me, you use parameters in Delphi to retain various settings then
this is of interest.
This is a real-life example so insert your own filepaths etc.
Set the HOSTS file on the client machine (located in
\winnt\system32\drivers\etc\ or \windows\ on 98)
In the HOSTS file you can have a number of different hostnames pointing
to the same IP address - so you can have e.g.
192.168.0.15 fibroserver # Name used for the IP test application
192.168.0.15 aldis-server # Real name for server for other use
I use 2 string variables for clarity. App_Name, App_Path. One of the thread
responses indicated that IP addressing may create an error if it encounters
'\' so this simple loop changes each '\' to '/'
App_Path:=ExtractFilePath(Application.ExeName); // result
c:/apps/fibrosys/thetford/
App_Name:='fibroserver:';
for n:=1 to length(App_Path) do
begin
if copy(App_Path,n,1)='\' then
App_Name:=App_Name+'/'
else
App_Name:=App_Name+copy(App_Path,n,1);
end;
// result fibroserver:c:/apps/fibrosys/thetford
IBDatabase1.DatabaseName:=App_Name+'Fibrosys.gdb'; // this will not work
.... open database etc....
This correctly opens fibroserver:c:/apps/fibrosys/thetford/Fibrosys.gdb on
the server. BUT it will fail with SQL error -901 on the client. The reason
is that there must be some TCP layer error which I have not resolved yet.
The following works - the string is exactly the same as the version above
when expanded. So the answer is to hard-code the location by the look of
things.
IBDatabase1.DatabaseName:=fibroserver:c:/apps/fibrosys/thetford/Fibrosys.gd
b;
On the client, both versions translate into
fibroserver://aldis_server/apps/fibrosys/thetford/Fibrosys.gdb
I hope this sorts out a few problems - it took quite a while for me to
resolve
ps - I have since put the location into a txt file and use a
listbox.loadfromfile to get the correct settings - make this a read-only
file if you use this idea. My final version is now going into all
applications where there is a possibility nof remote access or access from
a different IP segment
// Location of DataBase using settings in App_Data.Txt in App Folder
*********
// App_Data.Txt should be read-only, possibly hidden - allows for moving
to any
// Folder BUT needs to be exactly as per Folder location
App_Path:=ExtractFilePath(Application.ExeName);
Form1.App_PathBox.Items.Clear;
Form1.App_PathBox.Items.LoadFromFile(App_Path+'App_Data.Txt');
App_Name:=Form1.App_PathBox.Items[0];
Form1.App_PathBox.Items[0]:='IP='+App_Name;
Form1.App_PathBox.Items[1]:='DS='+App_Path;
if IBDatabase1.Connected=True then
IBDatabase1.Connected:=False;
IBDatabase1.DatabaseName:=App_Name;
IBDatabase1.Connected:=True;
Alan J Davies
email: alan@...