importing data into ms access with odbc

Upload: senyadnoire

Post on 03-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Importing Data into MS Access with ODBC

    1/13

    Importing Data into MS Access with ODBC(Page 1 of 6 )

    Microsoft Access allows the user to import data originating from a large number of different

    kinds of data sources. Access can establish a live link to the data, acting like a front end using

    data from the back end. This tutorial takes the reader step-by-step through the process of linkingto ODBC databases so that the data can be manipulated in MS Access for the benefit of the enduser.

    Converting any form of data to a format to fit the rows and columns of a table is at the core of

    RDBMS. Legacy data in flat files have the inherent limitations of data corruption, problems of

    maintenance, size, and so forth. When they get moved to the RDBMS, the individual pieces of

    data find themselves in well structured tables, and by establishing relationships of different kindsbetween these tables, finding data, and maintenance of data becomes a lot easier and a lot faster.

    One of MS Access's strength lies in its capability to import data originating from a large number

    of different kinds of data sources, text files, spread sheet files, and so on. In importing data, it hastwo different capabilities. It can import a table outright into the MS Access database, or it can

    establish a live link to the tables. In this second capacity, the data can stay where it is and theAccess application acts as a front end using data from the backend. However, since it is file

    based, it functions more like a file server type of application. This makes Access well suited for

    multi-user scenarios, where several applications can feed off the single, main database.

    This tutorial takes the reader step-by-step through the process of linking to ODBC databases so

    that the data can be manipulated in MS Access for the benefit of the end user. As previously

    mentioned the data can also be imported, and this will be considered in a future tutorial. It isassumed that MS Access is installed (this tutorial used the following version: MS Access 2002

    (10.2627)-SP1 on windows XP-professional platform) on the desktop, which has access to theother databases, files that needs to be linked.

  • 7/28/2019 Importing Data into MS Access with ODBC

    2/13

    Importing Data into MS Access with ODBC - Establishing a link to a database file(Page 2 of 6 )

    Create a blank mdb file. The new database will have a default name, db1.mdb and it is

    recommended that you change this name to reflect your application. Here, it is called

    LinkToImport.mdb. The database is created in the default directory, C:\My Documents. At thispoint there are no user created objects, except for several utilities needed to create various

    objects, such as tables, queries, forms, reports, and so forth, as shown in this picture.

    Establishing a Link

    Now click on File ->Get External Data-> Link Tables...as shown in this picture.

  • 7/28/2019 Importing Data into MS Access with ODBC

    3/13

    This opens up the My Documents folder for browsing, so that you can locate the file. It is quite

    possible that files may be located in other locations as well. Hence it is advisable that apreliminary search is made to determine the location of the various files. Clicking on the drop-

    down, Files of type: the various file types that Access can import into the database are displayed

    as shown.

  • 7/28/2019 Importing Data into MS Access with ODBC

    4/13

    The different file types supported are shown in the following list. In this tutorial we will be

    looking at the last item in the list, the ODBC databases.

    Microsoft Access(*.mda; *.mdb; *.mde) dBase III, IV and 5 (*.dbf) Microsoft Excel (*.xls) Exchange() HTML documents(*.htm, *.html) Outlook() Paradox(*.db) Text files with several extensions(*.csv, *.txt, *.asc, *.tab) ODBC databases

  • 7/28/2019 Importing Data into MS Access with ODBC

    5/13

    Importing Data into MS Access with ODBC - Configuring an ODBC Source(Page 3 of 6 )

    In order to connect to a database we need to have what is called an ODBC datasource. This is

    created using the 32bit ODBC Manager installed when Office 2000 is installed, or gets installed

    with the operating system. In Window XP Professional, you can get to the ODBC Administratorby going through Start ->Control Panel -> Administrative Tools -> ODBC Sources Short-Cut -

    >ODBC Data Sources Administrator. Now click on ODBC Data Sources (the previous screen

    shot) to open the picture shown next.

    This is a part of the ODBC Data Sources Administrator macro. There are two tabs, File Data

    Source and Machine data Source. By default, it opens up the File Data Source tab in the clickedposition. By choosing the Machine Data Source tab all the users of this machine and the system

    can use the data source. There are a number of data sources already created and these are shown

    in window.

    User Data Source and ODBC Drivers

    Now click on New... to open the next window, where you choose whether only you can access,or all the users of the machine can access this resource. Here, the User Data Source choice is

    made. Click Next.

  • 7/28/2019 Importing Data into MS Access with ODBC

    6/13

    This opens up the next window, where you make a choice as to the driver you may want to use.

    As you can see here, there are a large number of drivers for diverse kinds of data sources, suchMS Access, MS Excel, FoxPro, Oracle, and so on. This window is important as you can see the

    version and dates for the various drivers. We further assume that we will link to a file on an

    MSDE (Microsoft SQL Desktop Edition) database on the machine. After choosing SQL Serverwe click next.

    You will be shown a short summary screen indicating the type of datasource you created: (User

    data Source) and the driver you have chosen (SQL Server). Click Finish to this screen. This

    opens up the next window where you need to configure certain features of the MSDE database.

  • 7/28/2019 Importing Data into MS Access with ODBC

    7/13

    Importing Data into MS Access with ODBC - Configuring the New Data Source to MSDE(Page 4 of 6 )

    This brings us to the next window, Create a New Data Source to SQL Server, where you type a

    name for the ODBC data source you are creating. Here it is called LinkTut. You may give a

    description; here it is the title of this tutorial. Now click on the drop-down after the label, WhichSQL server do you want to connect to?:. This should show all the available servers, here the

    XPHTEK/Test instance of the MSDE database is chosen. Click Next.

    The window shown next pops up. In this window you need to choose the way you desire to get

    authenticated. There are two options, Windows integrated authentication, or SQL Server

    authentication. Whereas for the former you require a network logon, for the latter you require alogin name and password recorded in the SQL Server to which you are connecting. Here the

    former is chosen. You may also place a check mark to use other default configuration settings.

    Click next.

  • 7/28/2019 Importing Data into MS Access with ODBC

    8/13

    In this screen, the default database masteris brought up, but you can alter the default database.Here a database called myPubs has been chosen. You may accept the other defaults. Click Next.

    There are a number of settings which set up various options, but defaults are good enough for

    this tutorial. Click Next and then clickFinish to the window that shows up. You will come to thefinal window shown after the next picture. The picture shows all the configurational values you

    chose as well as those from the accepted defaults. If you find that the defaults are not the ones

    you want, you may edit the configuration settings by going through the same steps.

  • 7/28/2019 Importing Data into MS Access with ODBC

    9/13

    Finishing touches and testing the connectivity

    You may test the connection and then clickOK. The window that pops up shows LinkTut as a

    new DSN under the Machine Data Source tab as shown. Now click OK to this screen.

  • 7/28/2019 Importing Data into MS Access with ODBC

    10/13

  • 7/28/2019 Importing Data into MS Access with ODBC

    11/13

    Importing Data into MS Access with ODBC - Importing the tables from MSDE(Page 5 of 6 )

    The following screen shows up, where you make choices as to the tables you want to link to.

    Tables are the only objects you may link to. The prefix dbo for the tables indicate they are being

    linked with dbo permissions. Highlight the tables you want to link to, and clickOK. You mayalso save the password with the link so that you may not need to enter this information again.

    You are done!

    Now the link to the tables has been established as seen in this picture. Four tables have been

    successfully linked using the ODBC Connection to the MSDE database. Table names have come

    over with a dbo prefix and the icons show that they are ODBC database tables.

  • 7/28/2019 Importing Data into MS Access with ODBC

    12/13

    Importing Data into MS Access with ODBC - Imported table/Original table comparison (Page 6 of 6 )

    Design view comparison

    These two pictures show the design of the tables that were linked and the original table design in

    the MSDE database. The data types in SQL Server are different from those of MS Access, and

    the linked table design features are not allowed to be altered.

  • 7/28/2019 Importing Data into MS Access with ODBC

    13/13

    Comparison of tables

    Summary

    This step-by-step procedure should help in establishing ODBC links to tables in MSDE. Theprocedure is generic and can be used for other databases which one can find, or download driversfrom third party vendors. As it was seen in this tutorial, the linked table data types will be those

    of the MS Access native type rather than of the originating database. The table design cannot be

    changed in the linked tables. Using MS Access with linked tables can effectively shield

    applications from data and make data accessible to a number of applications sharing the samedata.