我有一个 .NET maui 项目,其中包含 SQLite 数据库。我想将
Categories
表与远程 SQL Server 同步,但我在 Android 平台上遇到以下错误(在 Windows 中,它工作正常),知道我使用了 Dotmim.Sync 库:
发生错误:[InternalEnsureScopeInfoAsync]覆盖:False..[InternalGetSchema Async]..[InternalGet TableSchema Async)。表:产品.. 从服务器接收结果时发生传输级别错误。 (提供者:TCP 提供者,错误:2-连接终止)
这是我的代码:
// Class Categories
public class Categories
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string NomCategorie { get; set; }
public string DateCreation { get; set; }
}
// Connection string for SQL Server
string connectionString = @"Data Source=SQL server ;Initial Catalog=db ;User Id= admin;Password=Password";
// Initialization of Categories
SqlSyncProvider serverProvider = new SqlSyncProvider(connectionString);
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "mydb.db");
SqliteSyncProvider clientProvider = new SqliteSyncProvider(dbPath);
// Configuring synchronization for the "Categories" table
var setup = new SyncSetup("Categories");
// Create the synchronization agent and execute the synchronization
SyncAgent agent = new SyncAgent(clientProvider, serverProvider);
var result = await agent.SynchronizeAsync(setup);
这是 SQL Server 中的
Categories
表:
我在网上进行了多次搜索,但找不到任何信息。
我想将类别表与远程 SQL Server 同步
是的,正如上面提到的链接,在移动设备上,我们无法直接访问远程 SQL Server 实例,我们需要在应用程序和 SQL 服务之间使用 API。
在毛伊岛,您可以使用
REST-based
Web 服务将数据发送到服务器或在服务器之间同步数据。
Representational State Transfer (REST)
是一种建筑风格
构建网络服务。 REST 请求通常通过 HTTPS 发出
使用与 Web 浏览器检索网页相同的 HTTP 动词
并将数据发送到服务器。
基于 REST 的 Web 服务通常使用 JSON 消息将数据返回给客户端。
更多信息,您可以查看文档:Consume a REST-based web service。