Linking Access To SQL Server
Linking Access To SQL Server
The dialog box displays DSN files. These files hold a description of a data source with all the information needed to locate and connect to it (known as the connection string). If you have already created one or more data sources they will probably be displayed here. The default location displayed is the Data Sources folder on your computer (usually C:\Program Files\Common Files\ODBC\Data Sources) but since a DSN file is merely the connection instructions and not the data source itself you can keep it anywhere you like.
Microsoft Access
Since you are creating a link for the first time you will have to make a new DSN file. Click the button marked New to open the Create New Data Source dialog box then scroll down the list of drivers and select SQL Server (Fig. 3).
If you know the name of the database (not the server name) to which you want to link you can specify it now by clicking the Advanced button on the Create New Data Source dialog box to open the Advanced File DSN Creation Settings dialog box. This already contains the first part of the connection string. Underneath it type DATABASE=<DatabaseName> replacing <DatabaseName> with the name of your chosen database (Fig. 4). In this example I am connecting to a table in the Northwind sample database on SQL Server.
Fig. 4 Add the name of the database you want to connect to.
Click OK to return to the Create New Data Source dialog box then click Next. Now enter a name for your new DSN file (Fig. 5). It will normally be stored in the Data Sources folder but if you want
Martin Green www.fontstuff.com 2
Microsoft Access
to keep it somewhere else click Browse and specify your chosen location. In this example I have given the DSN file the name NorthwindLinkDemo.
Click Next to display the last window of the dialog box. Here you will see all the information you have provided (Fig. 6). You can make changes here if you need to. If the driver requires more information to connect to the chosen data source it will prompt you at the time of connection. Check that the information is correct and click Finish.
At this point a new dialog box will open allowing you to specify more information about the link (Fig. 7). If you wish you can enter a description of the data source. Now open the list of available servers. There will be a short pause while the program searches for available servers (there may be several) before displaying a list of their names. Servers installed on the computer you are working on are also referred to as (local). Choose the server on which your target database is located and click Next.
In the next window you can specify how to log on to the server. You might need to seek advice from your SQL Server administrator before completing this stage. Server databases usually require a Login ID and password before you are granted access to their data. In this example (Fig. 8) I am choosing Windows NT authentication which uses my existing Windows login to log me on to the server. If your server requires a separate login you should choose the SQL Server authentication option. You can then optionally enter the required Login ID and password. If you dont enter them here the driver will prompt you for them each time it connects to the server.
Microsoft Access
Click Next. Since the server can host many different databases it is a good idea to specify at this stage which one you want to connect to. Place a tick in the box marked Change the default database to: and choose the name of your target database from the list (Fig. 9). Then click Next.
The final window contains advanced options that I wont get involved with here. Click Finish. Access displays a summary window with the option to test the connection (Fig. 10). To do this click Test Data Source. If everything is satisfactory a confirmation message is displayed (Fig. 11).
Microsoft Access
Click the OK button on the ODBC Microsoft SQL Server Setup window to complete the process. You have now finished creating the DSN data source which will help you connect to your target database. In future, when you want to connect to the same database you can make use of the same DSN file. You will only have to create a new DSN file if you wish to connect to a different data source.
Select the data source name then click OK. Now the driver will connect to the data source and retrieve a list of tables in the server database. Access displays this list in the Link Tables dialog (Fig. 13). Select the table you wish to link to (to save repeating the process you can select multiple tables if you wish) then click OK.
You new link is now displayed in the Tables section of the Access Database Window (Fig. 14) and can be treated like any other table. You can view and query its data (Fig. 15), build forms and reports based on it and enter or edit records (subject to any permissions set on the server).
Fig. 14 The link to the table is shown in the Access Database Window.