x


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.

more ▼

asked Jul 11 '11 at 11:35 PM

marek428 gravatar image

marek428
31 1 1 3

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

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.

more ▼

answered Jul 12 '11 at 05:29 PM

marek428 gravatar image

marek428
31 1 1 3

(comments are locked)
10|3000 characters needed characters left

People, where I can find the Oracle.DataAccess.dll and Oracle.DataAccess.Client to download?

more ▼

answered Jul 16 '12 at 04:08 PM

ThiagoBruxo gravatar image

ThiagoBruxo
1

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

Jul 17 '12 at 01:12 AM marek428
(comments are locked)
10|3000 characters needed characters left

People, where I can find the Oracle.DataAccess.dll and Oracle.DataAccess.Client to download?

more ▼

answered Jul 16 '12 at 04:07 PM

ThiagoBruxo gravatar image

ThiagoBruxo
1

(comments are locked)
10|3000 characters needed characters left

Ok, I stumbled around a bit and got somewhat further. I did the following:

  1. I found a copy of Oracle.DataAccess.dll on my computer and copied it to my project

  2. I added using Oracle.DataAccess.Client; to my imports

  3. 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();):

NotImplementedException: The requested feature is not implemented. 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?

more ▼

answered Jul 12 '11 at 02:27 AM

marek428 gravatar image

marek428
31 1 1 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x418
x232
x88
x4

asked: Jul 11 '11 at 11:35 PM

Seen: 1452 times

Last Updated: Jul 17 '12 at 01:12 AM