Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.


I have a problem in mobilink environment. I have an SQL anywhere 12 for consolidated database, and I want to deploy mobilink synchronization to android devices.

I make the model and everything in sybase central, I generate the ultralite database for clients, and I made a test, the generated ultralite database file synchronizes well when I start the ultralite database on windows environment.

When I want to deploy the generated UL databases to android device, sync fails.

First of all, I dont know how to deploy the generated database file to the android clients. I found a way on android emulator that I push the .udb file to the data/data/ folder and synchronisation goes well. This is not an elegant solution because I dont have write permission to that folder on the devices.

I've tried to add it to the ProjHome/assets/ or ProjHome/res/raw folders in my eclipse project, but DatabaseManager.Connect could not find the file.

My question is, I do it on the wrong way or the only way is to manually create the database and the schema on the devices in Java code?

Thanks for answers!

asked 13 Nov '11, 16:22

legezam's gravatar image

accept rate: 0%

This is going mainly from memory; I hope it is not too far off.

One way to deploy a database file is to include the file as a resource in your Android project. Add the file to a resource folder in your project named resraw. On the first start up of the client, you need code like this to read the database file out of the resources and store it in the file system.

InputStream is = getResources().openRawResource(R.raw.my_db.udb);
FileOutputStream os = openFileOutput("my_db.udb", MODE_PRIVATE);
byte[] buff = new byte[4096];
int n;
for(;;) {
    n =;
    if (n < 0) break;
    os.write(buff, 0, n);

You need to specify the database file in your configuration, like this:

ConfigFileAndroid config = DatabaseManager.createConfigurationFileAndroid("my_db.udb", this);

Here I have just put the file name, which is the root of your application folder (data/data/com.example.package). If you wish to put the database file in a subfolder you will need to use the path in the call to createConfigurationFileAndroid().

Some people like to use the MobiLink file transfer capability to download the database file on first synchronization, but that is an advanced technique and I wouldn't investigate it until you have everything working.

permanent link

answered 13 Nov '11, 19:28

Tom%20Slee's gravatar image

Tom Slee
accept rate: 29%


The file path for private files can be obtained as in the following code fragment:

        Connection conn;
        try {
              config = DatabaseManager.createConfigurationFileAndroid(
                getFilesDir().getPath() + File.separator + "my_db.udb",
            conn = DatabaseManager.connect(config);
            // ...
        } catch(ULjException ex) {
            // ...

Note that my_db.udb is created in this example as a file that is private to your application, and it is removed when your application is uninstalled. If you want the database to be on external persistent storage, there are ways to do that, but you get the idea anyway.

(14 Nov '11, 13:57) Andy Quick

Thanks for the answers, my project is now working well!

(14 Nov '11, 16:18) legezam
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 13 Nov '11, 16:22

question was seen: 3,718 times

last updated: 14 Nov '11, 18:37