2013-05-30 62 views
2

解决sqllite db与zumero同步问题(使用xamarin.ios)时出现问题。我安装我的sync命令:调用zumero_sync时出现异常

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

我已经设置了数据库名与此:

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

希望有人能看到我在做什么不正确?谢谢。

+0

我们可以看到实际打开/注册SQLiteConnection的代码吗? –

+0

确定的事情:var conn = new SQLiteConnection(“Data Source =”+ dbPath); \t \t \t conn.Open(); \t \t \t conn.ZumeroRegister(); – user2420225

回答

1

第一个问题,我看到,这可能是不负责你所得到的错误:

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

从你的代码片段看来,你可能会传递dbPath到新的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; 
    } 

希望这有助于。

+0

非常感谢您的回复。我认为文档中对我来说不明确的一点是:“第一个是附加的应该同步的SQLite数据库的名称(通常是'main')”。这是我的本地数据库名称的完整路径吗?
user2420225

+0

SQLite允许将多个数据库文件附加到一个SQLite连接句柄。每一个都被命名。默认数据库名为'main'。 zumero_sync()的第一个参数是附加数据库的名称,通常是'main'。 –

+0

SQLite数据库文件的文件系统路径不会传递给zumero_sync()。您只需将该路径作为参数传递给您用来打开SQLite文件的任何函数。 –

相关问题