Migrating Access Database to SQL Server
page 3 of 6
by Amrita Dash
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 39052/ 62

Upsizing Process

The Upsizing Wizard upsizes an Access database to a new or existing SQL Server database or new access project by migrating data and data definitions and then moving database objects to the new database structure.  The upsizing wizard provides different options for migrating the table attributes, such as indexes, validation rules, defaults and table relationships.  One should always choose the DRI (Declared Referential Integrity) option under the table relationships to enforce referential integrity.  The upsizing wizard adds a “CS” suffix to the current access database name and stores this ADP project in the same location as the existing Access Database.

After migrating the tables and queries, the upsizing wizard creates a report that provides a detailed description of all the objects created and any errors encountered during the process.  It provides information about Database details (size, device names etc.), upsizing parameters (table attributes chosen for upsizing, table information including column names, data types, indexes etc.), table relationships and any errors encountered (tables not created, inadequate permissions, queries not upsized, validation rules skipped etc.).

Access and SQL Server vary in the way data is stored, the data types available and the storage capabilities.  All the tables that are upsized should be manually inspected.  So after upsizing the database through the Upsizing Wizard, we compared the tables in the access database and SQL Server according to the Upsizing Wizard Report and then made necessary changes to the SQL tables.  All the column names, data types and the index property were checked and modified if required.  All access database data types were converted to their equivalent in SQL.

ACCESS                                              SQL

Number                                      Int/TinyInt/SmallInt

Yes/No                                                Bit

Text                                          Char/Nchar/Varchar  

Currency                                    Money

Date/Time                                  Datetime/SmallDatetime

Memo                                         Text/Ntext

OLE Object                                 Binary/Image

AutoNumber/AutoIncrement           Identity

Only simple SELECT queries were converted to views.  SQL statements in record source, control source or row source of the forms, reports and controls were not converted.  The Modules and Macros also remained the same.

Changes Made After Upsizing the Database

Some features of access are not supported by SQL server, so one has to manually analyze and rectify any such issues during and after upsizing process.

1. The Forms, Reports, Modules and Macros are imported from the Access .mdb file.  From the File ->Get External Data ->Import options all forms, reports, modules and macros were imported.

2. Then the queries were changed.  Access queries can be divided into 3 types.

Views: These are the simple SELECT statements with no input parameters or return values.  These are used as virtual tables.

Stored Procedures: These are the queries that accept input parameters.  INSERT, DELETE and UPDATE statements were also converted to SQL Stored procedures.

User-defined Functions: These are the queries that accept some input parameters and return a single value or a table.  These are the subroutines that are used repeatedly in the application.

3. To make the .adp file access data from the SQL Server we changed the connection string and converted the DAO code to its ADO equivalent.  The connection string was made pointed to the SQL Server database.

Data Access Object (DAO)

DAO is a data access technology primarily designed to use the Jet databases like Microsoft Access or dBase, FoxPro, etc.

ActiveX Data Objects (ADO)

ADO uses the OLE DB technology to gain access to any type of data source.  The ADO object model is based on three types of objects namely Connection, Command and Record set. The connection object holds data source connection information like data source name, its location, the user id and password, the name of the OLE DB provider, etc.  The command object is used to execute SQL commands, queries and stored procedures.  The Record set object holds the results returned by the queries and used for adding records to the tables and updating the database.  In ADO, "CurrentProject. Connection" determines the connection string.

The connection string is:

Provider=Microsoft.Access.OLEDB.10.0; Persist Security
 Info=False; Data Source=192.168.10.3; User ID=sa; Initial Catalog= Database
 Name; Data Provider=SQLOLEDB.1

Opening and Adding Value to a Record Set

Let us now examine how to open and add value to a recordset using DAO and ADO.

Listing 1 - DAO    

Dim db as Database
Dim rs as DAO.Recordset
Set db = CurrentDb( )
Set rs = db.OpenRecordset(“tblPeople”)
rs.Edit
rs(“TextFieldName”) = “New Value”
rs.Update

Listing 2 - ADO

Dim rs As New ADODB.Recordset
rs.Open "tblPeople", CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic           
rs.AddNew
rs("TextFieldName ") = NewValue
rs.Update
rs.Close

Executing a Query

Listing 3 - DAO

db.Execute "SELECT ……………………………."

Listing 4 - ADO

Dim CommandText As String
CommandText = "SELECT……………………….."
rs.Open CommandText, CurrentProject.Connection, _
adOpenStatic, adLockReadOnly, adCmdText   

These changes were made throughout the code in the application.

4. The record source, control source or the row source of all the forms and reports remained unchanged after upsizing.  So we had to manually change the record source properties of all the forms and reports used.  The record source of all the Forms and Reports were modified to make them compatible with the SQL.  Listed below are some keywords that need to be changed for making them compatible with SQL Server.

ACCESS                                              SQL

TRIM                                         LTRIM/RTRIM

DISTINCTROW                             DISTINCT

IIF (expr)                                   CASE…WHEN

TRUE/FALSE                                1/0

& (for string concatenation)           +

FORMAT ( )                                 CONVERT ( )

CINT                                          CAST

UCASE                                       UPPER

LCASE                                        LOWER

ORDER BY in Views                       Not Supported

NOW ( )                                     GETDATE ( )

In Access the ISNULL () function returns 1 if the supplied parameter is NULL and 0 if it is not.  In SQL Server there are two parameters and the function works more like a CASE statement.

5. When a Form’s Record Source takes some parameters it has to be changed to a Stored Procedure and the parameters are to be passed through the input parameter property of the form.

Record Source: Stored Procedure Name

Input Parameter: [Forms]! [Form Name]! [Fieldname]

The Sub forms record sources that took the input value from the Main Form are converted to stored procedures so that they will be populated according to the value in the main form.


View Entire Article

User Comments

Title: Mr   
Name: Ajayi Gbolahan
Date: 2011-10-17 12:54:49 PM
Comment:
This is exactly the challenge i am confronted with at present i hope this will solve my promlem
Title: Academic Professor   
Name: Dr. Fekry Fouad
Date: 2010-08-01 10:42:12 AM
Comment:
Hi

Finally I got what I was looking for , it is an excellent step to migrate from ACCESS database into SQL and VB.NET.

I am Egyptian professor , currently I am on Saudi Arabia for consultancy (maily migration) , I would like to know more - if possible - about the methodology . in case you like the idea , please advise how we can cooperate , a lot of business and the backlog of access is so much , all of them are very much willing to have a saved migration.

Please send this answer to info@ittg.org

Regards

Dr. Fekry Fouad
00966560037271
Title: Academic Professor   
Name: Dr. Fekry Fouad
Date: 2010-08-01 10:40:13 AM
Comment:
Hi

Finally I got what I was looking for , it is an excellent step to migrate from ACCESS database into SQL and VB.NET.

I am Egyptian professor , currently I am on Saudi Arabia for consultancy (maily migration) , I would like to know more - if possible - about the methodology . in case you like the idea , please advise how we can cooperate , a lot of business and the backlog of access is so much , all of them are very much willing to have a saved migration.

Regards

Dr. Fekry Fouad
00966560037271
Title: SQL Svr DBA   
Name: KLM
Date: 2010-04-09 9:10:03 AM
Comment:
Hello Amrita.
I am currently involved in Migrating our Access2007 based application back-end (database) to SQL Server2005.
That said, I am using the client – server application approach that requires me to modify the ADO connect string.
Thus my question to you is:
How do I or where do I go to change the Connect string in the generated __.adp project file?

Thank you.

KK.

Please send this answer to kkmore@yahoo.com
Title: Migration   
Name: Sudhir Kumar
Date: 2010-01-29 6:12:37 AM
Comment:
i neeed urgently a code to transfer access table to sql server 2000
please help out
Title: Mr   
Name: Keith
Date: 2009-12-17 8:51:46 AM
Comment:
This type of article helps new computer profeshnals.
Title: migration   
Name: ashish
Date: 2009-07-13 9:37:39 AM
Comment:
i neeed urgently a code to transfer access table to sql table
please help out
Title: stored procedures   
Name: raimund popp
Date: 2007-04-12 10:12:25 AM
Comment:
did you also find a way how to get the sql-property of a stored procedure like querydefs(xx).sql

regards
raimund
Title: Covert excel file data into a MSSQL server databases   
Name: indu
Date: 2007-01-30 9:50:26 PM
Comment:
I want to upload a Excel file datas into MSSQL serve databae
Title: Great Article   
Name: Mike
Date: 2007-01-22 3:41:25 PM
Comment:
That has to be one of the best examples I have seen, saving me hours of writing stored procedures. Great example, especially the DAO / ADO comparison.
The only suggestion is to remove the space from the line:
rs("TextFieldName ") = NewValue
it should read rs("TextFieldName") = NewValue as that extra space cause Access to Error on Item not in collection (Error 3265). Thanks for saving me many hours.
Title: Problems with relation database   
Name: Ananda
Date: 2006-12-05 2:44:27 AM
Comment:
Hi!

Its excellent article.
But problem is relational database.
If you have primary id of one table as foreign key to another table then exporting database by this way will not slove that problem.
Relation will not work as the new id will be different that what you have in your your foreign table.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-20 12:55:36 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search