2

Having an issue getting started with syncing sqllite db with zumero (using xamarin.ios). I have setup my sync command :

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

but am getting an 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 ()

I have set the dbName with this:

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

Hopefully someone can see what I am doing incorrectly? Thanks.

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
user2420225
  • 97
  • 2
  • 10

1 Answers1

1

The first problem I see, which is probably not responsible for the error you are getting:

The dbfile argument to zumero_sync() needs to be the name of the dbfile on the server, which is different from the name/path of the corresponding dbfile on the client.

From your code snippets, it looks like you may be passing dbPath to new SQLiteConnection(), which is correct, but also passing the same string into the @dbfile parameter, which would be, er, less correct. :-)

On the client, management of the SQLite file is your responsibility, and Zumero does not care. Files are identified, of course, by their path.

On the server, management of the SQLite file is entirely handled by the server, and files are identified by a name. The namespace is flat, and the naming rules are strict. A dbfile name on the server must contain only lower-case letters and digits, and it must begin with a lower-case letter.

As for the error, I'm wondering if the SQLite file exists? Here's a snippet from the Tasky sample:

    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;
    }

Hoping this helps.

Eric Sink
  • 342
  • 1
  • 7
  • Thank you very much for your responses. I think the point that is not clear for me in the documentation is: "The first one is the name of the attached SQLite database which should be synchronized (usually 'main')". Is this is the full path to the name of my local database?
    – user2420225 May 30 '13 at 15:32
  • SQLite allows multiple database files to be attached to one SQLite connection handle. Each one is named. The default database is named 'main'. The first parameter to zumero_sync() is the name of the attached database, usually 'main'. – Eric Sink May 30 '13 at 23:01
  • The filesystem path of your SQLite database file is not passed to zumero_sync(). You only need to pass that path as the argument to whatever function you use to open the SQLite file. – Eric Sink May 30 '13 at 23:03
  • "The first parameter to zumero_sync() is the name of the attached database, usually 'main'" is the part i find ambiguous -> is the name 'main' then an alias to the attached database? (and then different names/aliases are created for each subsequent database files as they are attached). Sorry for my not grasping this. – user2420225 May 31 '13 at 10:38