ODBCDatabase.DataSource

From Xojo Documentation

Property (As String )
aODBCDatabase.DataSource = newStringValue
or
StringValue = aODBCDatabase.DataSource

Supported for all project types and targets.

The connection string to be used to establish a connection to an ODBC database. The connection string can either contain only the DSN name, or a string containing one or more keywords defined for the driver.

Notes

If only the DSN is passed, then the UserName and Password properties are used for the connection. If the connection string contains keywords, then the UserName and Password properties are ignored. See your driver documentation for information about which keywords are supported.

Pass an empty string ("") to the DataSource property to get an open-file dialog box. It will prompt you to choose a list of defined DSNs. The DataSource property may be updated by the ODBC driver with additional parameters used after a connection is made.

For examples of connection strings for various databases, visit http://www.connectionstrings.com.

Examples

This example prompts the user to select a Data Source:

Var db As New ODBCDatabase
db.DataSource = ""
Try
db.Connect
// proceed with database operations
Catch error As DatabaseException
MessageBox("Error: " + error.Message)
End Try

This example specifies the DSN information to connect to a Microsoft Access database:

Var db As New ODBCDatabase
db.DataSource = "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\TestAccessDB.mdb;Uid=Admin;Pwd=;"
Try
db.Connect
// proceed with database operations
Catch error As DatabaseException
MessageBox("Error: " + error.Message)
End Try