Connection to MS Access database
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I would like to connect a Microsoft Access database into Revit. This database contains some historical information about elements and a column with the Element Ids in Revit. The main idea is to display information of this database when clicking on an element.
I wrote the following C# code to connect to my database and read information:
// Connection string and SQL query string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Users\MHelene\Desktop\Data\Tests\WallsDB.accdb"; string strSQL = "SELECT * FROM Table1"; // Create a connection using (OleDbConnection connection = new OleDbConnection(connectionString)) { // Create a command and set its connection OleDbCommand command = new OleDbCommand(strSQL, connection); // Open connection try { if (connection.State != ConnectionState.Open) { connection.Open(); } // Execute command using (OleDbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string RevitID = reader.GetValue(5).ToString(); string name = reader.GetString(2); } } } catch (Exception ex) { message = ex.Message; return Result.Failed; } }
Unfortunately, I received an error for the bold line namely, when I try to open my connection. See the screenshot of the error:
I spent a few days trying to fix it and I tested all the solutions proposed on internet but I begin to lose hope. In Visual Studio, I can connect a database without any problem (Tools>Connect to Database…). However, within Revit plug-in I am still facing the same problem of database connection. So did I miss something with Revit?