views:

253

answers:

3

When updating a DataTable with 1850-ish new rows to a FbDataAdapter I get a NullReferenceException during execution.

Usually it succeeds in inserting around 1200 records, sometimes more, sometimes less...

However when stepping through the code with the debugger, it sometimes inserts the entire recordset, no problem.

I am using the Firebird ADO.NET DataProvider v2.1.

Any ideas? Thanks!

StackTrace:

System.NullReferenceException was unhandled by user code   Message="Object reference not set to an instance of an object."   Source="FirebirdSql.Data.FirebirdClient" StackTrace:
       at FirebirdSql.Data.FirebirdClient.FbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
       at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
       at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
       at DBTools.MergeDB.DataAccess.DatabaseHelper.UpdateDataTable(Int32 connectionIndex, DataTable dataTable) in C:\Workspaces\DatabaseTools\Releases\Latest\Sources\DBTools\DBTools.MergeDB\DataAccess\DatabaseHelper.cs:line 74

InnerException:

+2  A: 

I found this thread: http://osdir.com/ml/db.firebird.dotnetprovider/2006-04/msg00058.html

which may suggest a solution.

If that doesn't work for you, I suggest grabbing the source of the Firebird data provider and having a look in there to see if you can spot the problem. If not, try adding some error handling (e.g. logging exceptions to a textfile) to the Firebird code that's causing the problem, then compile that code and use it instead of the current Firebird.Data.dll (or whatever it's called).

If you can isolate the problem, then you can contact the Firebird developers and let them know about it... or even better, submit a fix! That way you get working code and you get to give something back to the open-source community.

Ian Kemp
A: 

Besides Ian's suggestions, I'd also try the new .Net Provider 2.5.
http://www.firebirdsql.org/index.php?op=files&id=netprovider

Douglas Tosi
A: 

Thanks for the suggestions!

After a bit of research I concluded the NullReferenceException was a side-effect of the actual Exception. Basically the update took too long, and timed out after about 60 seconds.

I altered the connection string to allow transactions (Enlist=true;) and added a TransactionScope around the code with a timeout of TimeSpan.MaxValue:

using (var scope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.MaxValue))
{
 ...
}

This solved the problem... I am, however, going to look into the Firebird Client source for the reason why the actual exception (timeout) is not correctly cascaded to the caller.

Yannick M.