gpt4 book ai didi

sqlite - 调用 zumero_sync 时出现异常

转载 作者:行者123 更新时间:2023-12-03 15:30:51 25 4
gpt4 key购买 nike

开始将 sqllite db 与 zumero 同步时遇到问题(使用 xamarin.ios)。我已经设置了我的同步命令:

cmd.CommandText = 
@"SELECT zumero_sync(
'main',
@server_url,
@dbfile,
zumero_internal_auth_scheme('zumero_users_admin'),
@credentials_username,
@credentials_password,
@temp_path
);";

cmd.Parameters.AddWithValue ("@server_url", "https://zinst*****.s.zumero.net");
cmd.Parameters.AddWithValue ("@dbfile", dbPath);
cmd.Parameters.AddWithValue ("@credentials_username", "myusername");
cmd.Parameters.AddWithValue ("@credentials_password", "*mypassword*");
cmd.Parameters.AddWithValue ("@temp_path", System.IO.Path.GetTempPath());

但我得到一个异常(exception):
Unhandled managed exception: Object reference not set to an instance of an object (System.NullReferenceException)
at System.Data.SQLite.SQLiteConnection.GetPointer () [0x00000] in <filename unknown>:0
at System.Data.SQLite.SQLiteConnection.ZumeroRegister () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Data.SQLite.SQLiteConnection:ZumeroRegister ()

我已经用这个设置了dbName:
string personalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string dbName = "***.db";
string dbPath = Path.Combine ( personalFolder, dbName);

var conn = new SQLiteConnection ("Data Source=" + dbPath);
conn.Open ();
conn.ZumeroRegister();

希望有人能看到我做错了什么?谢谢。

最佳答案

我看到的第一个问题可能与您遇到的错误无关:

zumero_sync() 的 dbfile 参数需要是服务器上 dbfile 的名称,与客户端上相应 dbfile 的名称/路径不同。

从您的代码片段看来,您可能正在将 dbPath 传递给 new SQLiteConnection(),这是正确的,但也将相同的字符串传递给了 @dbfile 参数,这将是,呃,不太正确。 :-)

在客户端,SQLite 文件的管理是你的责任,Zumero 不关心。当然,文件是通过它们的路径来识别的。

在服务器上,SQLite 文件的管理完全由服务器处理,文件由名称标识。命名空间扁平,命名规则严格。服务器上的 dbfile 名称只能包含小写字母和数字,并且必须以小写字母开头。

至于错误,我想知道SQLite文件是否存在?这是 Tasky 示例的片段:

    private SQLiteConnection GetConnection ()
{
bool exists = File.Exists (_path);

if (!exists)
{
SQLiteConnection.CreateFile (_path);
}

var conn = new SQLiteConnection ("Data Source=" + _path);

if (!exists)
{
do_sync (conn);
}

return conn;
}

希望这会有所帮助。

关于sqlite - 调用 zumero_sync 时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16826765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com