Contents Previous Next sqlconnect

Connecting to a Data Source
Syntax sqlconnect(connection string)
sqlconnect(
connection stringtimeout)
See Also sqlexec , sqldisconnect

Description
Creates a connection with the data source specified in the character row vector, connection string. The value of connection string must be a valid connection string for the data source that you are connecting to. See the ODBC documentation for your data source. If present, the argument timeout must be an integer scalar that specifies the number of seconds operations against this connection should proceed before timing out.

The sqlconnect function uses a 'DSN-less' connection to establish a connection with an ODBC driver. That is all information to establish a connection is provided in the connection string argument and a DSN for the desired datasource does not need to be established. The Data Access Toolbox supports connections to any data source for which an ODBC compliant driver has been installed. Select the Drivers tab in the Data Sources tool available from the Control Panel of your system to review the drivers available on your system.

The sqlconnect function must be called before using any other functions in the Data Access Toolbox. All of the functions in the Data Access Toolbox operate on the connection that was established by the most recent call to sqlconnect. If a data source connection has already been established when sqlconnect is called, the previous connection is dropped, (disconnected).

Examples

Connecting to an MS Access Database on a local Machine
If at the O-Matrix prompt you enter
     sqlconnect("driver={Microsoft Access Driver (*.mdb)};Dbq=c:\omwin\omsql\Contacts.mdb;UID=;PWD=")
O-Matrix will create a connection to sample Contacts.mdb provided with the Data Access Toolbox. (If you installed to a directory other than the default you will need to edit the value of Dbq in the above connection string.)

Connecting to an MS Access Database on a Network Share
You can access databases that are located on network shares. If, at the command prompt you enter
     sqlconnect("driver={Microsoft Access Driver (*.mdb)};Dbq=\\Harmonic\temp\Contacts.mdb;UID=;PWD=")
O-Matrix will connect to the Contacts.mdb database located in the temp directory on the server Harmonic.

Connecting to a local SQL Server Instance
If, at the O-Matrix prompt you enter
     sqlconnect("driver={SQL Server};server=(local)\NetSDK;Integrated Security=SSPI;database=northwind")
O-Matrix will create a connection to the Northwind database running on SQL Server with the local NetSDK server. If you are running SQL Server you may have to edit this string to reflect the name of your server.

Connecting to an Oracle Database Using the Microsoft Driver
If, at the O-Matrix prompt you enter
     sqlconnect("driver={Microsoft ODBC for Oracle};server=OracleServer.world;UID=myUsername;PWD=myPassword")

Connecting to a local MySQL Database
If, at the O-Matrix prompt you enter
     sqlconnect("driver={MySQL ODBC 3.51 Driver};server=bplaptop;database=test;user=beau;")
O-Matrix will connect to the test database on the MySQL server on bplaptop.

Connecting to Databases Interactively
Many ODBC drivers will display a dialog prompting for relevant information when the provide connection string is incomplete. This is useful when the connection string parameters are unknown or if you do not want to hard wire user authentication information into your application. For example, if you enter
     sqlconnect("driver={MySQL ODBC 3.51 Driver};")
The MySQL ODBC driver will display a dialog prompting for connection information.