Database.Connect

From Xojo Documentation

Method

Database.Connect() As Boolean

Supported for all project types and targets.

Connects to the database so that you can begin using it. Before proceeding with database operations, test to be sure that Connect returns True.

Notes

If Connect returns False, you should also check the ErrorCode and ErrorMessage.

Sample Code

SQLite

Dim dbFile As FolderItem
dbFile = GetOpenFolderItem("")

If dbFile <> Nil Then
Dim db As New SQLiteDatabase
db.DatabaseFile = dbFile
If db.Connect Then
MsgBox("Connected to " + dbFile.Name)
Else
MsgBox("Error: " + db.ErrorMessage)
End If
End If

PostgreSQL

Dim db As New PostgreSQLDatabase

db.Host = "localhost"
db.UserName = "postgres"
db.Password = "dbexample"
db.DatabaseName = "postgres"

If db.Connect Then
MsgBox("Connected to PostgreSQL!")
Else
MsgBox("Error connecting to PostgreSQL: " + db.ErrorMessage)
End If