PostgreSQL NilObjectException Error - Why?

Hello Everyone,

A call to connect to a PostgreSQL database gives the following error:

Here is the code which has this error:

[code] db = new PostgreSQLDatabase
db.host = “127.0.0.1”
db.port = 5432
db.DatabaseName = “Xojo_DB”
db.UserName = “XojoUser”
db.password = “secret”

If db.connect then
'The computer connected to the database
'MsgBox “Successfully connected to the database”
Else
MsgBox " can not connect to db "
Msgbox db.errormessage
Return
End If

Dim err as OLEException
MsgBox err.Message[/code]

There is a global property in Window1 that has the following:

db as PostgreSQLDatabase

I am guessing that I am missing something simple. The NilObjectException is shown with the bottom code highlighted with the IDE for the line MsgBox err.Message. If the OLEException is commented-out, the database will update, delete, and perform normally.

Does anyone have some helpful thoughts on what I need to do to prevent the NilObjectException from occurring and to offer insight on why this is happening?

Thanks for your help, :slight_smile:

Eugene

Dim err as OLEException MsgBox err.Message // err is Nil

Palm->Forehead

Thanks Eli :slight_smile:

I think what you meant to write is

Exception err As OLEException

Hi Kem,

Yes, you are right. LOL, I need to have the morning cup-of-coffee before programming :slight_smile:

Thank you.

Which command do you expect to raise an OLEException ?

Hi Maximilian,

I wasn’t expecting any exceptions, which is what was confusing. Eli kindly pointed to the section of code that tweaked my coffee-deprived memory and Kem politely supplied the correct code. :slight_smile: