cancel
Showing results for 
Search instead for 
Did you mean: 

UltraLiteJ check if database is already created

Former Member
0 Kudos
2,455

I'd like to connect to an existing DB or to create one and create tables if they don't exist. The problem is that the app just breaks, the VS debugger stops at line IConnection cn = DatabaseManager.Connect(config); The program does not enter into the catch clause.

public static IConnection GetConnection(Context context)
    {
        IConfigPersistent config = DatabaseManager.CreateConfigurationFileAndroid("MobileDb1.udb", context);

        try// Connect, or if the database does not exist, create it and connect
        {
            IConnection cn = DatabaseManager.Connect(config);
            return cn;
        }
        catch (ULjException e)
        {
            IConnection cn = DatabaseManager.CreateDatabase(config);
            CreateDatabaseTables(cn);
            InsertDemoValues(cn);
            return cn;
        }
    }
Former Member
0 Kudos

More info: I am using VS2010 with Mono for Android 4.4.55

chris_keating
Product and Topic Expert
Product and Topic Expert
0 Kudos

Have you double checked that the database in fact does not exist in this test. I have to ask because this methodology works in ULj proper on Android. If if is not working with MONO, it may be a problem with MONO. Is the cn null after the connect? Can you do a simple operation i.e., create table t(id integer primary key with that connection?

Former Member
0 Kudos

In addition to Chris's comments, I am wondering if you are deriving classes from our UltraLiteJ interfaces. We do not have classes like IConnection or IConfigPersistent, or methods like Connect (upper case C) in DatabaseManager. If there are derived classes involved, make sure that ULjExceptions are not being handled in the derived class without being re-thrown.

Former Member
0 Kudos

the debugger does not succeed to row return cn; it just stops,just like I have stopped it from the menu

Former Member
0 Kudos

This is where I started from Sybase Ultralite With Mono

Former Member
0 Kudos

Could you please attach me a working example?

chris_keating
Product and Topic Expert
Product and Topic Expert
0 Kudos

We are investigating this issue and will report our findings. While that is ongoing, you could capture the exception as a Java.Lang.Exception instead.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member

This works with UltraLiteJ APIs:

        ConfigFileAndroid config = null;
        Connection conn;
        try {
            config = DatabaseManager.createConfigurationFileAndroid("test.udb", this);
            Log.d("test", "connecting to database");
            conn = DatabaseManager.connect(config);
        }
        catch (ULjException e) {
            if (e.getErrorCode() == ULjException.SQLE_ULTRALITE_DATABASE_NOT_FOUND) {
                try {
                    Log.d("test", "creating database");
                    conn = DatabaseManager.createDatabase(config);
                    // create tables...
                }
                catch (ULjException ee) {
                    Log.e("test", ee.toString());
                }
            }
        }

I am not familiar enough with Mono for Android to definitively address your issue.