Reputation: 9
I am working in Microsoft Visual Studio Community 2022 (64-bit) - Preview, .Net Maui, Azure Web App and SQL Server and have followed the examples given for the ToDo sample. I am successfully able to collect data from another website and then save it into my remote tables.
private async Task InitializeAsync()
{
// Short circuit, in case we are already initialized.
if (_initialized)
{
return;
}
try
{
// Wait to get the async initialization lock
await _asyncLock.WaitAsync();
// Create the offline store definition
//var connectionString = new UriBuilder { Scheme = "file", Path = Constants.OfflineDatabasePath, Query = "?mode=rwc" }.Uri.ToString();
var connectionString = new UriBuilder { Scheme = "file", Path = Constants.DatabasePath, Query = "?mode=rwc" }.Uri.ToString();
var store = new OfflineSQLiteStore(connectionString);
// Define the offline tables
store.DefineTable<Profile>();
store.DefineTable<ProfileStore>();
store.DefineTable<Employee>();
store.DefineTable<EmployeeJob>();
store.DefineTable<Payroll>();
store.DefineTable<PayrollDetails>();
var options = new DatasyncClientOptions
{
OfflineStore = store,
HttpPipeline = new HttpMessageHandler[] { new LoggingHandler() }
};
// Create the datasync client.
_DatasyncClient = new DatasyncClient(Constants.ServiceUri, options);
// Initialize the database
await _DatasyncClient.InitializeOfflineStoreAsync();
// Get a reference to the offline tables.
_ProfileTable = _DatasyncClient.GetOfflineTable<Profile>();
_ProfileStoreTable = _DatasyncClient.GetOfflineTable<ProfileStore>();
_EmployeeTable = _DatasyncClient.GetOfflineTable<Employee>();
_EmployeeJobTable = _DatasyncClient.GetOfflineTable<EmployeeJob>();
_PayrollTable = _DatasyncClient.GetOfflineTable<Payroll>();
_PayrollDetailsTable = _DatasyncClient.GetOfflineTable<PayrollDetails>();
**await _DatasyncClient.PushTablesAsync(); ** <-- This is what fails
// Set _initialized to true to prevent duplication of locking.
_initialized = true;
}
catch (Exception)
{
// Re-throw the exception.
throw;
}
finally
{
_asyncLock.Release();
}
}
Sometimes, it gets into a state where the _DatasyncClient.PushTablesAsync fails.
HResult = -2146233088
ex = {"Push operation has failed. See the PushResult for details."}
PushResult = {Microsoft.Datasync.Client.Offline.PushCompletionResult}
Errors[0]:
Status = PreconditionFailed
I have logging on, by using:
var options = new DatasyncClientOptions
{
OfflineStore = store,
HttpPipeline = new HttpMessageHandler[] { new LoggingHandler() }
};
_DatasyncClient = new DatasyncClient(Constants.ServiceUri, options);
it shows (I scrubbed some data):
[HTTP] >>> PUT https://<myapp>.azurewebsites.net/tables/employeejob/02a9b6696aa341bcabc4aba2491c1aea
[HTTP] >>> If-Match: "AAAAAAAAUlU="
[HTTP] >>> ZUMO-API-VERSION: 3.0.0
[HTTP] >>> User-Agent: Datasync/6.0.0.0
[HTTP] >>> User-Agent: (lang=Managed;os=Microsoft Windows 10.0.22621/Microsoft Windows NT 10.0.22621.0;arch=X64;version=6.0.0.0;test)
[HTTP] >>> X-ZUMO-VERSION: Datasync/6.0.0.0 (lang=Managed;os=Microsoft Windows 10.0.22621/Microsoft Windows NT 10.0.22621.0;arch=X64;version=6.0.0.0;test)
[HTTP] >>> Content-Type: application/json; charset=utf-8
[HTTP] >>> {"id":"02a9b6696aa341bcabc4aba2491c1aea","employeeID":"268315","profileDBID":"c6e7ea7d-3dde-48c3-a582-186e594d8d3f","role":"Manager","startDate":"2019-12-30T08:00:00Z","endDate":null,"version":"AAAAAAAAUlU="}
[HTTP] <<< PreconditionFailed Precondition Failed
[HTTP] <<< Date: Fri, 06 Oct 2023 08:22:58 GMT
[HTTP] <<< Server: Microsoft-IIS/10.0
[HTTP] <<< ETag: "AAAAAAAAUnc="
[HTTP] <<< X-Powered-By: ASP.NET
[HTTP] <<< Content-Length: 686
[HTTP] <<< Content-Type: application/json; charset=utf-8
[HTTP] <<< Last-Modified: Fri, 06 Oct 2023 07:29:01 GMT
[HTTP] <<< {"employeeID":"268315","profileDBID":"c6e7ea7d-3dde-48c3-a582-186e594d8d3f","role":"Manager","startDate":"2019-12-30T08:00:00","endDate":null,"id":"02a9b6696aa341bcabc4aba2491c1aea","updatedAt":"2023-10-06T07:29:01.806+00:00","version":"AAAAAAAAUnc=","deleted":false}
Exception thrown: 'Microsoft.Datasync.Client.Offline.PushFailedException' in System.Private.CoreLib.dll
Data does successfully go to my online database, so I know my code is working, but occassionally it fails like this, and will never recover. Only thing I can do is delete my local offline database (or I guess use the Purge function)
There doesn't appear to be anything wrong with my data.
await _DatasyncClient.PushTablesAsync();
expected it to push the local database records up to the online database.
I've researched the error and read something about an Azure ETag setting, but not sure if its something I can set on the Microsoft.DataSync Client
Frustrating because I would love to have a functioning offline database that can sync to the online database, but I may have to do this manually.
Upvotes: 1
Views: 599
Reputation: 9
Answer is to just move away from Microsoft.Datasync, its not ready for prime time. I'm now doing Entity Framework locally and replicating manually up to Azure.
Upvotes: -1