I tried different ways and googled a lot for the error but no luck so far.
I am trying to make a function which can update an existing shard mapping but I get the following exception.
Microsoft.Azure.SqlDatabase.ElasticScale.ShardManagement.ShardManagementException: Store Error: Error 515, Level 16, State 2, Procedure __ShardManagement.spBulkOperationShardMappingsLocal, Line 98, Message: Cannot insert the value NULL into column 'LockOwnerId', table 'TEST-POS.__ShardManagement.ShardMappingsLocal'; column does not allow nulls. INSERT fails.
Though I created Create Shard and Delete Shard functions and they are working fine. But I get the above error while updating or creating a mapping.
Following is my code:
PointMapping<int> pointMapping;
bool mappingExists = _listShardMap.TryGetMappingForKey(9, out pointMapping);
if (mappingExists)
{
var shardLocation = new ShardLocation(NewServerName, NewDatabaseName);
Shard _shard;
bool shardExists =
_listShardMap.TryGetShard(shardLocation, out _shard);
if (shardExists)
{
var token = _listShardMap.GetMappingLockOwner(pointMapping);
var mappingUpdate = new PointMappingUpdate { Shard = _shard, Status = MappingStatus.Online };
var newMapping = _listShardMap.UpdateMapping(_listShardMap.MarkMappingOffline(pointMapping), mappingUpdate, token);
}
}
I get the same error either I supply the token or not. Then I also tried to supply token in this way MappingLockToken.Create(), but then I get different error that correct token was not provided. It is also obvious because token is different.
_listShardMap.UpdateMapping(offlineMapping, mappingUpdate, MappingLockToken.Create());
Microsoft.Azure.SqlDatabase.ElasticScale.ShardManagement.ShardManagementException: Mapping referencing shard '[DataSource=cps-pos-test-1.database.windows.net Database=Live_MSA_Test_Cloud]' belonging to shard map 'ClientIDShardMap' is locked and correct lock token is not provided. Error occurred while executing procedure
I also checked the LockOwnerId in the [__ShardManagement].[ShardMappingsGlobal] table in the database and this is the ID = 00000000-0000-0000-0000-000000000000
I though I am getting null insertion error because token Id is zero, so I updated it manually to 451a4da0-e3d4-42ac-bdc3-5b57022693d0 in database by executing an update query. But it did not work and I get the same Cannot insert the value NULL into column 'LockOwnerId' error.
I am also facing the same Null error while creating a new mapping and I do not see in the code where to provide a token while creating a mapping. Following is code.
PointMappingCreationInfo<int> newMappingInfo = new PointMappingCreationInfo<int>(10, newShard, MappingStatus.Online);
var newMapping = _listShardMap.CreatePointMapping(newMappingInfo);
I searched it a lot on google and downloaded some sample applications as well, but I am not able to find the solution. I will highly appreciate any kind of help.