【问题标题】:Exception when calling zumero_sync调用 zumero_sync 时出现异常
【发布时间】:2013-05-30 01:59:16
【问题描述】:

在开始将 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());

但我遇到了一个异常:

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();

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

【问题讨论】:

  • 我们可以看到您实际打开/注册 SQLiteConnection 的代码吗?
  • 确定:var conn = new SQLiteConnection ("Data Source=" + dbPath); conn.打开(); conn.ZumeroRegister();

标签: sqlite zumero


【解决方案1】:

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

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

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

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

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

至于错误,我想知道SQLite文件是否存在?这是 Tasky 示例中的一个 sn-p:

    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 数据库的名称(通常是'main')”。这是我的本地数据库名称的完整路径吗?
  • SQLite 允许将多个数据库文件附加到一个 SQLite 连接句柄。每一个都有名字。默认数据库名为“main”。 zumero_sync() 的第一个参数是附加数据库的名称,通常是 'main'。
  • SQLite 数据库文件的文件系统路径未传递给 zumero_sync()。您只需将该路径作为参数传递给用于打开 SQLite 文件的任何函数。
  • "zumero_sync() 的第一个参数是附加数据库的名称,通常是 'main'" 是我觉得模棱两可的部分 -> 是名称 'main' 然后是附加数据库的别名? (然后在附加的每个后续数据库文件中创建不同的名称/别名)。很抱歉我没有掌握这一点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-06
  • 2017-10-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多