- Home /
How can I connect the database and catch a value by Access
It always show errors
"System.Data.Odbc.OdbcException: ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'. at System.Data.Odbc.OdbcConnection.Open () [0x00000] in :0 UnityEngine.Debug:Log(Object) RaderData:ReadStudent(String) (at Assets/Connection/Scripts/RaderData.cs:55) RaderData:Start() (at Assets/Connection/Scripts/RaderData.cs:16)"
This is my code:
using UnityEngine;
using System.Collections;
using System;
using System.Data;
using System.Data.Odbc;
public class RaderData : MonoBehaviour{
string text = string.Empty;
public void Start(){
ReadStudent(Application.dataPath + "/Nutrap.accdb");
}
internal void ReadStudent(string filetoread){
string connection = "Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" + filetoread;
string sqlQuery = "select * from Student";
OdbcConnection con = new OdbcConnection(connection);
OdbcCommand cmd = new OdbcCommand(sqlQuery,con);
DataTable dt = new DataTable("Student");
try{
con.Open();
OdbcDataReader reader = cmd.ExecuteReader();
dt.Load(reader);
reader.Close();
con.Close();
}
catch (Exception ex){
//text = dt.Rows[3][1].ToString();
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();
}
}
public void OnGUI(){
GUI.Label(new Rect(10,10,500,200),text);
}
}
Thanks for the help :(
Answer by MarkFinn · Nov 25, 2013 at 10:54 PM
I'm pretty sure that's just it not being able to find your "/Nutrap.accdb" file.
Do a
Debug.Log(connection)
after that variable is set, and check that the file-path matches the reality on your pc.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122708im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
SQL connection problem 0 Answers
Is it possible to open a web page inside Unity? 2 Answers
Unity - wait for data to load from database 1 Answer
connect sqlite3 into unity 2 Answers
How do I connect to an Oracle Database? 6 Answers