I recently tried to use access database with C# code inside a little Revit plugin but it crash when I use OleDbConnection.Open()
Here is my snippets:
CPFMainModelView mainModelView;
static readonly string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ThomasLECUPPRE(Letit\source\LIB_MainDB.accdb";
public UserDBManager(CPFMainModelView cmmw)
{
mainModelView = cmmw;
try
{
RetrieveprojectList();
}
catch (Exception ex)
{
mainModelView.Texte = $"{ex.Message}\n\n{ex.StackTrace}\n\n{ex.InnerException}\n\n{ex.Data}";
}
}
public void RetrieveprojectList()
{
using (OleDbConnection con = new OleDbConnection(connectionString))
{
con.Open();
OleDbCommand command = new OleDbCommand("SELECT Ref FROM FolderCategory", con);
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
mainModelView.Texte += $"\n{reader["Ref"]}";
}
}
}
Here is a view of my tiny db in access
What did I miss ?
I have already see these thread : C# - OleDbConnection.Open() causing a crash Simple C# connection to .accdb file
Before use "Provider=Microsoft.ACE.OLEDB.12.0" and build the solution for X86 only, I was using "Provider=Microsoft.Jet.OLEDB.4.0" and build solutino for Any CPU but this thread (in french sorry) tell to it another way.
Thank you for help.