You are on page 1of 13

Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

MS SQL SERVER 2008

MS Access to MS SQL Server


Exercise 1 Create a MS Access SQL Project .................................................................. 2
Exercise 2 Importing to a MS Access SQL Project........................................................... 4
Exercise 3 Viewing MS Access SQL Project in MS SQL Server........................................ 7
Exercise 4 Inserting data via MS SQL to a MS Access SQL Project.................................. 7
Exercise 5 Import/Export MS Access databases to a MS SQL dat abas e. ............................. 7

This guide show s how to either link or import MS Access database s to MS SQL Server.

Exercise s 1-4 cover the development of a Database Project which has a front -end MS
Acce ss user interface with the tables held under a back-end MS SQL Server.

Exercise 5 show s how to import/export a MS Access database to MS SQL Server.

The guide can be used to transfer new or existing MS Acce ss databa se s to MS SQL
Server. i.e. the transfer of table s and data to a central server.

Completing thi s guide you will be able to generate client server based database s.

The workstations run MS Acce ss front end facilities to acce ss the data and provide
information.

The server runs MS SQL Server to hold and maintain a central bank of data.

Review the following link:


http://www.sql servercentral.com/columnists/awarren/linkingaccesstosql server.asp

A guide on: how to develop dat abase projects.

Front end development provided by MS Access for users


Back end development provided by MS SQL Server for developers

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7: 1
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

Students should read the background information provided before


attempting the development of professional projects

Exercise 1 Create a MS Access Project


a. In this example we will set up a MS Access Project by creating a new connection to MS
SQL Server.
Create a new project.

b. Click to create a new connection bet ween MS Access and


MS SQL Server. The adp1 (or filename chosen) holds the Data Connection String (Data
Binding Information) linking the MS SQL Server tables to the MS Access Project. In the
example below the adp1 is replaced with library

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7: 2
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

c. Click on the will load up the appropraiate servers to choose from. The following Data
Connection Form typically will display the home PC name.

d. Select finish

e. Having created a new MS Access Project called library we may create the tables as you
normally do in MS Access. However remember the tables and dat a will be held under
MS SQL Server.

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7: 3
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

Exercise 2 Importing to a MS Access Project


f. You may also import any existing MS Access Database into a new MS Access project.
This is effectively trans ferring a workstation based database to a client server based
setup.

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7: 4
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

g. The example below demonstrat es the conversion of MS Access library.mdb to a MS


Access Project library.mdb. The project will have the tables and data held under MS
SQL Server.
Using the MS Acce ss database LIBRARY provided.

LIBRARY DATABASE
MS Acce ss 2000 MS Acce ss 2000 Zip

Library.mdb

h. Select All tables. (Also select required forms, reports, etc). Note you cannot trans fer MS
Access Queries over to MS SQL Server. These queries need to reflect the new location
of tables and data. Simply generated new queries.

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7: 5
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

i. Click OK to import tables and data. You may interrogate and maintain the library
database as before.
However you can also interrogate the data under MS SQL Server.

MS Access Project MS SQL Server


library.adp Librarysql.mdf

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7: 6
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

Exercise 3 Viewing MS Access Project in MS SQL Server


j. The librarysql is viewable under MS SQL Server 2008
The view below shows the librarysql under MS SQL Query Analyzer
Run MS SQL Server Management Studio

Inserting Data
Exercise 4 Inserting data to a connected MS SQL / MS Access Project

Data can be inserted into the librarySQL database in either platform. Please not e data is held
under MS SQL environment.

Exercise 5 Import/Export MS Access to MS SQL database

Transfer Access database to SQL Server 2008


Open SQL Server Management Studio and connect to the database server you
want to import your Access database into. Under Databases, right-click and
choose New Database.

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7: 7
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

Give it a name and configure the other settings as needed and click OK. Now we
need to right-click on the database we just created and choose Tasks and then
Import Data.

On the Data Source dialog box, scroll up until you see Microsoft Access.

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7: 8
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

Next to File, click on Browse and navigate to the Access database you want to
import and click Open. Note that the database cannot be in Access 2007 format
as SQL Server 2008 does not recognize it! So if you have a 2007 Access
database, first convert it to the 2002-2003 Access format by going to Save As.

Go ahead and click Next to choose the destination. Since you right-clicked on the
database you wanted to import the data into, it should already be picked in the
list.

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7: 9
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

Click Next and then specify how you want to transfer the data from Access to
SQL by choosing either Copy the data from one or more tables or Write a
query to specify the data to transfer.

In most cases, if you want to just transfer the entire database, you should choose
the first option. If you want only a portion of the data from a particular table, you
can write out the SQL query. Click Next.

By default all the tables should be selected and if you click the Edit button under
Mapping, youll see the the destination database will create all of the tables to
match whats in the Access database.

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7:10
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

Here I have only one table in my Access database. Click Next and then choose
whether to execute immediately or to save it as a file to perform later.

Click Next and then click Finish. Youll then see the progress of the data transfer
as it occurs.

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7:11
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

After it is completed, youll see the number of rows transferred for each table in
the Message column.

Click Close and you should now have all of your Access data nicely imported into
a SQL Server 2008 database, which you can then use for whatever you like.

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7:12
Chapter 7: MS SQL SERVER 2008 SQLQuery MS Access linking to MS SQL Server

Sample MS Access databases to convert to MS SQL databases.


Convert the following MS Access databases to MS Access projects with a link to the MS SQL
Server.
Bodgitt Builders Estate Agents Karlston Library

dd.BodgittBuilders.doc dd.EstateAgent.doc dd.KarlstonLibrary.doc

dd.BodgittBuilders.mdb dd.EstateAgent.mdb dd.KarlstonLibrary.mdb

Mansha Nawaz MS SQL SERVER 2000 QA MS Access linking to MS SQL Server Chapter 7:13

You might also like