Attaching A Database

I put together a window with several datafields and subclassed some of them and I’m ready to attach a database to store the data entered. So in the Navigator I go to App, right click for Add to App, the list appears, I click Database, the sub-list of databases appears. But they are all greyed out. Can’t add New SQLiteDatabase. Is there another way to do this? Thanks in advance for the help.

Start with the language reference -
Anything specific, ask from there.

I thought that was what I was doing with the above actions, but I’ve now tried to add a class to app called ‘AptDB’ with DataBase as its super. Its added, but can’t do anything, can’t connect to an SQLite DB etc. All databases still greyed out on the Event Handler sub-list. What next? Thanks in advance for any help.

I have never “added” a DB to a project unless it was an existing SQLite db file.
I use Postgres and MySQL mostly.
The server can contain the app and connect to local host or connect to an external database (or both!).

Most people on here create the DB (SQLite) at startup and then connect to it through the file system.

Have a look at the example projects in Xojo and cut your teeth on those.

Your use of DB will highly depend on your usage.
If its an app on win/Lin/Mac storing some settings or single user then use SQLite.
If hundreds of connections use Postgres etc.

User Guide Book 3: Framework, Chapter 4: Databases explains how to connect to all the databases supported by Xojo and has sample code you can use.

The “Add Database” mechanism is a quick and dirty shortcut for absolute beginners to be able to get “something” going. It comes with certain inherent limitations and is quickly abandoned as you progress in your knowledge of Xojo. I’d recommend skipping that phase altogether, as connecting to a database in code is very simple. Decide what scope the database needs to be (limited to one window only or application-wide) and how long the database connection needs to exist (short, discrete bursts of connectivity where you open and close the connection for each action, or keep it open for the duration of the app). Most people choose application wide access for the duration of the app. In that case,

Add a global property for the database.
Connect to the database in app.Open

That’s all there is to it.