does anybody has an idea why connections to ODBC databases won’t run in Unity5 (64 bit) anymore (in Unity4 it worked perfectly)?
Another user wrote about the same problem here (trying to connect to a xls file):
I got the same problem when I try to connect to an access database file:
OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified System.Data.Odbc.OdbcConnection.Open ()
In Unity4 the code below works without errors and reads the stored data from the database. The path to the file is correct too, checked this multiple times …
Thanks for any help!
Kind regards!
using UnityEngine;
using System.Collections;
using System;
using System.Data;
using System.Data.Odbc;
public class Database : MonoBehaviour
{
public string text = "";
void Start()
{
string path = Application.dataPath + "/DinnerDB.accdb";
ReadTable(path);
}
internal void ReadTable(string filetoread)
{
string connection = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + Application.dataPath + "/DinnerDB.accdb" + ";";
string sqlQuery = "select * from Zutaten";
OdbcConnection con = new OdbcConnection(connection);
OdbcCommand cmd = new OdbcCommand(sqlQuery, con);
DataTable dt = new DataTable("Zutaten");
try
{
con.Open();
OdbcDataReader reader = cmd.ExecuteReader();
dt.Load(reader);
reader.Close();
con.Close();
}
catch (Exception ex)
{
Debug.Log(ex.ToString());
}
finally
{
if (con.State != ConnectionState.Closed)
{
con.Close();
}
con.Dispose();
}
if (dt.Rows.Count > 0)
{
text = dt.Rows[1][1].ToString();
}
}
}
Going out on a limb on a possible solution (my apologies if you have already checked this).
There are actually two separate ODBC admin tools for windows. one is 32 bit and one is 64 bit. sounds like you’ve made a 32 bit DSN, but not a 64 bit one.
on a 64 bit windows install
C:\Windows\System32\odbcad32.exe is the 64 bit version
C:\Windows\SysWOW64\odbcad32.exe is the 32 bit version
purely guessing, but I wonder if previous unity builds only used the 32bit DSNs, and they added 64 bit DSN support in 5.
I had the same issue and this Q&A was very helpful to narrow down my problem.
On a Windows 7 64 bit machine with Unity 64 bit, the Unity’s Mono System.Data.Odbc class relies on the odbc32.dll that is located in Windows\System32 and not the one in Windows\SysWOW64. I found out the driver wasn’t listed in the odbcad32.exe administration tool located in Windows\System32.
Installing the 64 bit version of Microsoft Access Database Engine 2010 Redistributable solved my issues as I now have the correct 64 bit driver listed in the odbcad32.exe application.
The drivers can be downloaded from here: https://www.microsoft.com/en-us/download/details.aspx?id=13255
The driver name in all the connection strings in the code must be updated with the new driver’s name (that can be seen with the odbc administration tool).
I am now using Unity 5.3 64 bit and connecting successfully to the data source, in my case a dbf file.
I am sure this doesn’t cover all the error IM002 cases but if you have this issue, this is one thing you want to exclude anyway.