- Home /
How to connect to Oracle?
Hello, for two days I'm trying to connect to Oracle from Unity, but no luck... Maybe anybody can say how to do that? Or maybe give code part of connecting?
What client connection protocol are you trying - ODBC, .NET/ODAC, etc
Tried ODBC and ODAC, both give errors, while in normal .net application, they both works...
ODBC:
OdbcConnection cn=new OdbcConnection("Driver={$$anonymous$$icrosoft ODBC for Oracle}; UID=user; PWD=PASS; Server=XE;");
OdbcCommand cmd =new OdbcCommand("select * from sku",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();
First line throw:
InvalidProgramException: Invalid IL code in :.cctor (): method body is empty.
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Warehouse$$anonymous$$anager.Start () (at Assets/Scripts/Warehouse$$anonymous$$anager.cs:37)
And this one put Unity in not responding
ODAC:
string connectionString = "Data Source=XE; User ID=user; Password=PASS;";
OracleConnection dbcon = new OracleConnection (connectionString);
Debug.Log("Connected");
dbcon.Open ();
OracleCommand dbcmd = dbcon.CreateCommand ();
string sql = "SELECT * from sku";
dbcmd.CommandText = sql;
OracleDataReader reader = dbcmd.ExecuteReader ();
while (reader.Read ()) {
Debug.Log ((string) reader["skucode"]);
}
reader.Close ();
reader = null;
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery ();
dbcmd.Dispose ();
dbcmd = null;
dbcon.Close ();
dbcon = null;
Second line throw:
InvalidCastException: Cannot cast from source type to destination type. Oracle.DataAccess.Client.CThreadPool..cctor () Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Oracle.DataAccess.Client.CThreadPool Oracle.DataAccess.Client.OracleInit.Initialize () Oracle.DataAccess.Client.OracleConnection..cctor () Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Oracle.DataAccess.Client.OracleConnection Warehouse$$anonymous$$anager.Start () (at Assets/Scripts/Warehouse$$anonymous$$anager.cs:61)
No. I just moved to XNA and done what I want. But I think there must be somewhere tutorial for that, because 2 years passed, so somebody really had to make it.
Your answer
Follow this Question
Related Questions
Who can tell me how to connect to an Oracle Database?very grateful! 2 Answers
How do I connect to an Oracle Database? 6 Answers
SQLite Transaction Update Problem on Android 0 Answers
Where to store data about location 0 Answers
Wrap text textmesh 0 Answers