Access oracle database

does not work.

conn := ‘Provider=OraOLEDB.Oracle.1;Password=xxxxx;Persist Security Info=True;User
ID=xxxx;Data Source=bd’;
query := ‘select * from GEO_LAYER’;

id := Map1.AddLayerFromDatabase(conn, Query, True);
Map1.OgrLayer[id];
Map1.ShapeLayerFillColor[id] := clWhite;
Map1.ShapeLayerLineColor[id] := clBlack;
Map1.ShapeLayerLineWidth[id] := 1.5;
Map1.CursorMode := cmPan;
Map1.Redraw;
Map1.Refresh;
Map1.SetFocus;
if id <> 0 then
ShowMessage('Error ’ + IntToStr(id));

Hello @Silvio, and welcome.

Your statement is a little too vague. What is it that ‘does not work’?

  1. Does AddLayerFromDatabase seem to work (i.e. does it return an id >= 0)?
    a. If the layer is not added successfully, you should verify your connection string and existence of a table named GEO_LAYER.
  2. The second line Map1.OgrLayer[id] is unnecessary, and can be removed.
  3. If the layer is successfully added, is there an error that is occurring after that? or do you just not see the layer?

Please provide more information and we’ll try to help you figure it out.

Thanks.
Jerry.

Hello,
Thank you for your help.

I use this sequence of commands to load maps from a SQLSERVER database normally, but with Oracle database it doesn’t work.

  1. the string is correct;
  2. the table exists and has a field named “GEOMETRY”
    but:
  3. do not load the map;
  4. the “ID” returns -1;

Just to verify the connection, try something like the following (based on some sample code). One thing I noticed is that your connection string doesn’t have a GDAL prefix. For example, when connecting to SQL Server, you prefix the connection string with “MSSQL:” I’m not sure, but for ODBC, you may need a prefix like “ODBC:”. But try the following and see if you get back an error. Then we can take it from there.

private static string CONNECTION_STRING = "Provider=OraOLEDB.Oracle.1;Password=xxxxx,Persist Security Info=True;User ID=xxxx;Data Source=bd";

var ds = new OgrDatasource;

if (!ds.Open(CONNECTION_STRING))
{
    Debug.Print("Failed to establish connection: " + ds.GdalLastErrorMsg);
}

Thanks.

Hello,
Is it really possible to access spatial data from an oracle database?

Tanks

Yes, it should be possible. GDAL has a driver for Oracle Spatial (https://gdal.org/drivers/vector/oci.html). And I think you should also be able to use the ODBC driver (as specified here) (and it looks like you need the ODBC prefix, look at the samples provided by GDAL).

Did you try connecting using the sample code I provided? If you got an error, what was the error?

Jerry.

Good Morning,
I develop in delphi.
but it does not even show the error message.
Gives the message “acess violation”
Follow the routine

var
dt: OgrDatasource;

begin
// Oracle
conn: = ‘Provider = OraOLEDB.Oracle.1; Password = xxxxx, Persist Security Info = True; User ID = xxxx; Data Source = bd’;
query: = ‘select * from sgib.GEO_LAYER’;

try
dt.Open (conn);
except
on E: Exception of
begin
ShowMessage (‘Err:’ + E.Message);
end;
end;
end;

I think the access violation is because you did not allocate the datasource. I don’t know the Delphi syntax, but it may be something like

dt := New OgrDatasource;

OR, looking at some online samples, perhaps it’s something like

dt := CreateCOMObject(OgrDatasource) as IOgrDatasource;

Also, I think you will need to prefix your connection string with “ODBC:”, but you can try it both ways to see which works.

Regards,
Jerry.

Hi,
I continue to study how to connect to an oracle database using delphi 10.3 with Mapwingis 5.1.1.
follow my connection string and sql
conn: = ‘OCI: username / password @ server: port / DB’;
query: = ‘select * from table’;
follow my command
id: = Map1.AddLayerFromDatabase (conn, Query, True);
-> if id returns -1 then it went wrong.

What else can I do to make sure?

Thank you.

Hello,
I still can’t access oracle database.
But I did tests with sql server:
In version 4.9.6.1 it works perfectly and in version 5.1.1 does not load the polygon.