Navigation:  Programming Cookbook > Database Connectivity >

Connecting to a Data Source

Previous pageReturn to chapter overviewNext page

Now let's use the Database Connection interface to connect to the sample data source from Dolphin. We use an instance of DBConnection to do this and you will need a separate instance for each different data source that you intend to talk to. To connect to a data source you must:

1.Create a new instance of DBConnection
2.Set the data source name with #dsn:
3.Optionally, set the username with #uid:
4.Optionally, set the password with #pwd:
5.Finally, use #connect to make the connection

Try evaluating the following in a workspace.

c := (DBConnection new) dsn: 'NWind'; connect.

 

Note that the data source name (Nwind) is actually the name as it is known to the ODBC Administrator and not the underlying database file name (although in this case they are the same). Try displaying the contents of c.

a DBConnection('NWind')