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

asked 11 Feb '13, 03:35

Mariyan%20Marinov's gravatar image

Mariyan Marinov
1112
accept rate: 0%

edited 11 Feb '13, 03:52

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

(11 Feb '13, 03:37) Mariyan Marinov

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?

(11 Feb '13, 09:43) Chris Keating
Replies hidden

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.

(11 Feb '13, 09:50) Andy Quick
Replies hidden

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

(11 Feb '13, 09:52) Mariyan Marinov

This is where I started from Sybase Ultralite With Mono

(12 Feb '13, 02:39) Mariyan Marinov

Could you please attach me a working example?

(13 Feb '13, 03:25) Mariyan Marinov

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.

(13 Feb '13, 09:56) Chris Keating
showing 5 of 7 show all flat view

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.

permanent link

answered 13 Feb '13, 09:21

Andy%20Quick's gravatar image

Andy Quick
2.2k2737
accept rate: 45%

Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×159
×72

question asked: 11 Feb '13, 03:35

question was seen: 2,221 times

last updated: 13 Feb '13, 09:56