Table.Insert fails with "Workspace or data source is read only.(-2147220893)"

3786
3
01-03-2012 12:52 AM
YoavZobel
New Contributor
Hi, I've ran into the following bug:

Trying to write more than 1000 rows with point geometries, on some feature I get an error "Workspace or data source is read only.(-2147220893)", trying to insert this row again and the following rows succeeds.

The code is attached.

How can it be solved?

Thanks.
0 Kudos
3 Replies
LanceShipman
Esri Regular Contributor
Add the following two lines after you open the table.
  table.LoadOnlyMode(true);
  table.SetWriteLock();

Add the following after you finish inserting rows.
  table.LoadOnlyMode(false);
  table.FreeWriteLock();

LoadOnlyMode is usually a good choice when loading data. Setting it to true shuts down index update. Bulk update of indexes is much faster that single updates. Setting Load Only Mode to false, rebuilds all of the indexes. Without setting the write lock  and lock is established for each insert. This is slow. Calling SetWriteLock establishes a write lock on the table and holds it until FreeWriteLock is called or the table is closed.
0 Kudos
YoavZobel
New Contributor
Ok thanks!

It does solve the issue,
but I'm using various wrappers for the filegdbapi.dll like .net wrapper (VS 2008) and Gdal Ogr, where those methods aren't exposed.
The performance issue is less important in my case, I just need it to work.
So can inserting many point features work without calling those methods?

Thanks.
0 Kudos
LanceShipman
Esri Regular Contributor
Locking and poor system performance is likely the problem. If a write lock is not acquired using table.SetWriteLock and lock will be created for each insert. If system performance (a slow network or disk) is poor there is a chance that the lock will not be cleared before the next insert attempts to acquire a lock. Your choices are:

1) Use the VS 2010 .NET wrapper that we included in the 1.1 release of the API. It includes the SetWriteLock method.
2) Check the error returned in your insert loop and re-insert when you receive a -2147220893 error. You would want to limit the number of retries.
0 Kudos