Reputation: 399
I'm writing a C# plugin for Autodesk Navisworks that will iterate through a bunch of 3D elements and write their properties (Category and Family of the element for now) into an Azure database.
I'm using Dapper as ORM. When I try to insert the data in the database Navisworks crashes giving an unhadled exception.
I tried the ssame procedure with plain sql and everything works fine so I'm quite sure it's Dapper's Execute function giving the exception.
This is my object:
internal class NavisTest
{
public string Category { get; set; }
public string Family { get; set; }
public NavisTest(string category, string family)
{
Category = category;
Family = family;
}
}
This is the sql command:
const string navisTestSql = "insert into NavisTest " +
"(Category, Family) " +
"values (@category, @family);";
And this is the main logic:
using (SqlConnection connection = new SqlConnection(
NavisDbSettings.ConnectToDB().ConnectionString))
{
// Open connection to db
connection.Open();
using (SqlTransaction transaction = connection.BeginTransaction())
{
NavisTest navisTest = new NavisTest(
"Wall",
"Concrete Wall 01");
connection.Execute(NavisDbSqlCommands.navisTestSql, navisTest, transaction: transaction);
// Commit database transaction
transaction.Commit();
}
}
So when this runs Navisworks just crashes, but if I do with a normal SqlCommand everything works fine. (Also I basically copied the code to insert to the db from another application I have that works perfectly)
Also, if I try to surround the code in a try-catch clause, it still fails (it's an unhandled exception).
I really don't understand what I'm doing wrong.
Any ideas?
Upvotes: 1
Views: 275