[SOLVED] How to check if database is connected

How do you check if a database is connected?

In my test application I’m connecting to an Access database via the GetOpenFolderItem function but quite regularly in testing I’m forgetting to connect to the database and then errors are thrown upon my first call to any recordsets. Yes, I could run the GetOpenFolderItem function first thing automatically but I’d rather test if there is a connection to start with.

ps. I’m connecting via an ODBC connection.

I’m not sure I’m following. You are not connected unless you call ODBCDatabase.Connect. There won’t be any connection to start with unless you do that first.

What does GetOpenFolderItem have to do with connecting to an Access database?

Beta Tester? Mmmm

I want to know if there is a way to check if my ODBCDatabase variable “db” has been dimensioned or assigned.

I’m primarily concentrating on my SQL components at the moment, haven’t yet written any preference file type routines in order to record the last directory path and database filename information. This will be the approach to connecting to a database when done.

If it can’t be done, checking if a variable hasn’t been assigned then I’ll simply hardcode the directory path and database filename and connect that way until I get to working on my preference setup routine.

I hope this makes sense.

Sorry Lee, not sure how this impacts my issue.

Still not quite following you. Are you looking for something along the lines of

if db = nil then db = New ODBCDatabase ... end if

[quote=13727:@Tim Hare]Still not quite following you. Are you looking for something along the lines of

if db = nil then db = New ODBCDatabase ... end if [/quote]

Damn, so simple, yes this will do it.

Thanks Tim.