- Home /
How do I connect to an Oracle Database?
I am not certain of what connection string I should be using and if I have to copy specific dlls into my project?
Any help would be appreciated, thanks.
Answer by marek428 · Jul 12, 2011 at 05:29 PM
Ok, I found the answer - posting to help anyone else that may encounter this problem (give me some good karma if it helps :)
using System.Data.Odbc;
OdbcConnection cn;
OdbcCommand cmd;
cn= new OdbcConnection("Driver={Microsoft ODBC for Oracle};Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" + dbServer + ")(PORT="+ dbPort + "))(CONNECT_DATA=(SID=" + dbSID + ")));Uid=" + dbUsername + ";Pwd=" + dbPassword + ";");
cmd=new OdbcCommand(yourQuery,cn);
cn.Open();
Debug.Log("Connected");
OdbcDataReader rData = cmd.ExecuteReader();
while (rData.Read()){
Debug.Log("row" +rData[0] + " " + rData[1] );
}
Debug.Log(rData.FieldCount);
rData.Close();
cn.Close();
There were a number of problems I ran into with this implementation 1. I had to use the ODBC driver for Oracle as the Oracle and MS drivers did not work as I showed above (EDIT: below now as this one got up-voted). I am sure someone can get this to work, but I am not that good of a programmer. 2. The next problem is that Unity will crash as DataTable.Load does not work with the Oracle ODBC driver (although it works on the same DLL with the XLS implementation - odd no?). So that is why I have the "while (rData.Read())" as I am planning on populating the DataTable manually myself. It is working for me so far, although I am sure there is a far, far better way of doing this. 3. Any questions, please let me know.
Hi there. I am getting the following error: OdbcException: ERROR [I$$anonymous$$002] [$$anonymous$$icrosoft][ODBC Driver $$anonymous$$anager] Data source name not found and no default driver specified System.Data.Odbc.OdbcConnection.Open ()
Can you please tell from where you got the $$anonymous$$icrosoft ODBC for Oracle driver?
Hello, i would like to know if you have a link to download the ODBC driver, the one you used because there are a lot...
Cordially
Answer by marek428 · Jul 12, 2011 at 02:27 AM
Ok, I stumbled around a bit and got somewhat further. I did the following:
I found a copy of Oracle.DataAccess.dll on my computer and copied it to my project
I added using Oracle.DataAccess.Client; to my imports
Then I added the following code:
OracleConnection oCon = new OracleConnection(con); oCon.Open(); OracleCommand oCmd = new OracleCommand(); oCmd.Connection = oCon; oCmd.CommandText = yourQuery; oCmd.CommandType = CommandType.Text; OracleDataReader dr = oCmd.ExecuteReader(); dr.Read(); oCon.Close();
And it compiles! But unfortunately I received this error for my troubles (it fails on the oCon.Open();):
System.EnterpriseServices.ContextUtil.get_IsInTransaction () Oracle.DataAccess.Client.ConnectionDispenser.Open (Oracle.DataAccess.Client.OpoConCtx opoConCtx) Oracle.DataAccess.Client.OracleConnection.Open () (wrapper remoting-invoke-with-check) Oracle.DataAccess.Client.OracleConnection:Open () ReadExcel.readData (System.String source) (at Assets/Scripts/ReadExcel.cs:359) ReadExcel.OnGUI () (at Assets/Scripts/ReadExcel.cs:216) Does this mean Unity/Mono does not support Oracle? Or am I doing something else wrong that is above my pay grade?NotImplementedException: The requested feature is not implemented.
Answer by ThiagoBruxo · Jul 16, 2012 at 04:08 PM
People, where I can find the Oracle.DataAccess.dll and Oracle.DataAccess.Client to download?
Try here: http://www.oracle.com/technetwork/database/windows/downloads/index-101290.html
It gives you a lot to download, but it should be under the driver area.
Also, I wound up scrapping my oracle endeavor as there were too many bugs. I basically got it to work with limited features, things maybe better in the new version. Best of luck :)
What I often do is go to the NuGet Gallery, and find the NuGet Package for the library. Download that, and change the file type from .nupkg
to .zip
, and then you can usually find the DLL in one of those subfolders. For the Oracle.DataAccess one, it's in the lib
folder.
Answer by ThiagoBruxo · Jul 16, 2012 at 04:07 PM
People, where I can find the Oracle.DataAccess.dll and Oracle.DataAccess.Client to download?
Answer by jeffblumenthal · Jan 12, 2017 at 11:42 AM
I am having problems hitting an 11g instance using 5.5.0f3. My suspicion is the current set of drivers go up to 10g. Therefore I went 3rd party. I got https://www.devart.com/dotconnect/ working quickly. Note, I DO NOT work for them.
HTH
Your answer
Follow this Question
Related Questions
can Unity connect to Filemaker database? 2 Answers
How to integrate SQL database in game? 1 Answer
Android | online database 2 Answers
Firebase Connection error 0 Answers
connect sqlite3 into unity 2 Answers