# Access oracle database

**URL:** <https://mapwindow.discourse.group/t/access-oracle-database/263>\
**Category:** MapWinGIS\
**Created:** [September 26, 2019, 5:03pm UTC](https://mapwindow.discourse.group/t/access-oracle-database/263 "2019-09-26T17:03:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Silvio](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Silvio](https://mapwindow.discourse.group/u/Silvio)\
**Post date:** [September 26, 2019, 5:03pm UTC](https://mapwindow.discourse.group/t/access-oracle-database/263/1 "2019-09-26T17:03:10Z")

</div>

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));

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [September 26, 2019, 6:59pm UTC](https://mapwindow.discourse.group/t/access-oracle-database/263/2 "2019-09-26T18:59:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Silvio](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Silvio](https://mapwindow.discourse.group/u/Silvio)\
**Post date:** [September 26, 2019, 9:00pm UTC](https://mapwindow.discourse.group/t/access-oracle-database/263/3 "2019-09-26T21:00:07Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [September 26, 2019, 9:13pm UTC](https://mapwindow.discourse.group/t/access-oracle-database/263/4 "2019-09-26T21:13:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Silvio](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Silvio](https://mapwindow.discourse.group/u/Silvio)\
**Post date:** [September 27, 2019, 6:14pm UTC](https://mapwindow.discourse.group/t/access-oracle-database/263/5 "2019-09-27T18:14:55Z")

</div>

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

Tanks

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [September 27, 2019, 11:02pm UTC](https://mapwindow.discourse.group/t/access-oracle-database/263/6 "2019-09-27T23:02:55Z")

</div>

Yes, it should be possible. GDAL has a driver for Oracle Spatial ([https://gdal.org/drivers/vector/oci.html](https://gdal.org/drivers/vector/oci.html)). And I think you should also be able to use the ODBC driver ([as specified here](https://gdal.org/drivers/vector/oci.html)) (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.

---

<div class="post-metadata">

**Author:** ![Silvio](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Silvio](https://mapwindow.discourse.group/u/Silvio)\
**Post date:** [October 1, 2019, 11:31am UTC](https://mapwindow.discourse.group/t/access-oracle-database/263/7 "2019-10-01T11:31:41Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [October 1, 2019, 10:07pm UTC](https://mapwindow.discourse.group/t/access-oracle-database/263/8 "2019-10-01T22:07:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Silvio](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Silvio](https://mapwindow.discourse.group/u/Silvio)\
**Post date:** [December 18, 2019, 5:58pm UTC](https://mapwindow.discourse.group/t/access-oracle-database/263/9 "2019-12-18T17:58:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Silvio](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Silvio](https://mapwindow.discourse.group/u/Silvio)\
**Post date:** [December 23, 2019, 1:12pm UTC](https://mapwindow.discourse.group/t/access-oracle-database/263/10 "2019-12-23T13:12:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [January 5, 2022, 3:08pm UTC](https://mapwindow.discourse.group/t/access-oracle-database/263/11 "2022-01-05T15:08:54Z")

</div>


