- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there!
I ve read a lot of topic about trable connection to MS Access. It is not getting clear.
I have a small function:
static void Access()
{
string DataBase = @"C:\Users\UserName\Documents\Database1.accdb";// and the only one simple table inside
// Connection string and SQL query
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + DataBase;
string strSQL = "SELECT * FROM tbl1 order by Id";
// Create a connection
try
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
// Open the connection and execute the select command.
// Open connecton
connection.Open();
if (connection.State != System.Data.ConnectionState.Open)
{ return; }
// Create a command and set its connection
using (OleDbCommand command = new OleDbCommand(strSQL, connection))
{
// Execute command
using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
string Name = (string)reader["Name"];
int Id = (int)reader["Id"];
}
}
}
}
}
catch (OleDbException ex)
{
string msg = ex.Message;
throw;
}
}
This function works in simple program
static void Main(string[] args)
{
Access();
}
But kills revit without any exception here:
public Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
Access();
return Result.Succeeded;
}
catch (Exception ex)
{
string str = ex.Message;
throw ;
}
}
Could anyone to explain why?
Thanks forward!
Solved! Go to Solution.