Application crashes during OleDb insert operation with SQL Server Compact

I’m working with a SQL Server Compact database and having trouble with insert operations. My Vendors table has these fields:

VendorId - int, primary key, identity
CompanyName - nvarchar(100)  
AccessCode - nvarchar(100)

Every time I attempt to add a new record, my console app just crashes without throwing any catchable exception. Here’s the code I’m using:

var insertCmd = new OleDbCommand("INSERT INTO Vendors (CompanyName, AccessCode) VALUES(?, ?)", connection);

insertCmd.Parameters.AddWithValue("@CompanyName", companyName);
insertCmd.Parameters.AddWithValue("@AccessCode", accessCode);

insertCmd.ExecuteNonQuery();

What could be causing this crash? Query operations work perfectly fine on the same table, so the connection seems solid. I’ve tried wrapping it in try-catch blocks but the application terminates before any exception handling kicks in. Any ideas what might be going wrong with my insert statement?

sounds like a parameter ordering issue. with oledb you can’t mix named params like @CompanyName with ? placeholders - pick one approach. try removing the @ symbols and just use AddWithValue(“CompanyName”, companyName) or switch to all ? marks. silent crashes usually mean the oledb driver’s choking on malformed sql.

I hit the same issue with SQL Server Compact and OleDb. The problem’s usually how OleDb handles parameters differently than regular SQL Server. You’re using question marks as placeholders, which means OleDb wants positional parameters - but AddWithValue with named parameters gets confused. Try this: ditch the parameter names and just use AddWithValue with the actual values, or better yet, use the Add method and specify the data types explicitly. Also double-check your connection string has the right provider - should be Microsoft.SQLSERVER.CE.OLEDB.4.0 for Compact databases. When it crashes silently like that, it’s usually a provider mismatch or parameter binding problem, not a database constraint issue.

that’s strange - is your app really crashing or just freezing? compact db locks can make it seem like a crash. also, why oledb instead of sql ce provider? maybe check the event viewer to see if any errors show up?