Database.Connect

From Xojo Documentation
Jump to: navigation, search
Method

Database.Connect() As Boolean

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.

Examples

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
Personal tools
Namespaces

Variants
Actions
Main
Content
Starting Out
Dig Deeper
More Help
Toolbox
About