Home > Language Reference > Database Functions > DbConnect

DbConnect

The DbConnect function creates a connection to an ODBC database.

Usage

Used to connect to the Data Source Name used in subsequent Database functions.

Syntax

ret=DbConnect(<connection_string>)

Parameters

<connection_string>, string containing database connection information. The string contains a number of arguments and values separated by semicolons, the first argument must be DSN and its value is the data source name as configured in ODBC (see How to Create an ODBC Connection to a Database). Examples:
"DSN= DBTest"
"DSN=SQLTEST ;UID=MY_USER ;PWD=ABC"
"DSN=SQLTEST ;UID=USER2"

The arguments in <connection_string> depend on your database driver, see your database documentation for advanced settings.

Return value

ret, optional numeric return value. If the function successfully opens the database within the timeout value (30 secs by default, use #ActionTimeout to change this default value) , the return value is 0. If the function fails, the return value is a nonzero value (see Error Codes for Database Functions).

See also

DbBof
DbClose
DbDisconnect
DbEof
DbExecute
DbGetFieldNumeric
DbGetFieldString
DbMove
DbMoveFirst
DbMoveLast
DbMoveNext
DbMovePrev
DbRecordCount
DbSelect

Examples

DbConnect("DSN=DBTest") ' connection to ODBC database called DBTest
DbConnect("DSN=SQLTEST ;UID=MICHAEL ;PWD=ABC") ' connection to an ODBC database called SQLTEST for the user Michael using the password ABC