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

Problems Faced and Their Solutions

Complex queries

The cross tab queries and other complex queries were not converted to their equivalent in SQL.  We had to manually convert those complex queries to make them compatible with SQL Server. Those were converted to views, stored procedures or functions.

Write-Conflict Error

“This record has been changed by another user since you started editing it. If you save the record, you will overwrite the changes the other user made. Copying the changes to the clipboard will let you look at the values the other user entered, and then paste your changes back in if you decide to make changes.”

Parent!LastUpdateBy = CurrentUser( ) and Parent!LastUpdateDate = Date.  These two lines of code were not supported in Access ADP and we found this to be the reason for the Write Conflict error on the sub forms in our project.  We removed these two lines of code to avoid a write conflict error.  However, we had to add LastUpdatedBy = CurrentUser () and LastUpdateDate = Date only in the Save Button Function to update the forms at the end.  In this case, the main form did not get updated immediately after any modifications were made to the sub forms value.  It only got updated after pressing the “Save Button.”  The cause of write conflict error may be different for other ADP applications.  It may be due to not assigning a default value to a bit data type in SQL or due to some primary key problems.

The Write Conflict error may appear when two forms that update the same data source are opened at the same time.  The first form puts an edit lock on the record(s) and then the second form changes the record(s) and saves the changes.  When the first form tries to close and write back to the table, the changes that were made by the second form are detected.  This causes the error to be returned.

Docmd.TransferText and Docmd.TransferSpreadSheet

These commands are used to export records to a text file or an excel sheet with proper format and are not supported by Access ADP.

For the Docmd.TransferText Command we had to create a file system object and use that to write the whole record into a text file.  The record was fetched by executing a view or stored procedure.  All the columns of each record were written into the text file using a loop.  The CreateTextFile and Writeline function of the file system object were used to write the records into a specific text file in a specified location.

Listing 5

In Access: 
DoCmd.TransferText acExportDelim, , "QueryName", sPath & "\FileName.txt", True, , 65001
 
Modified Code:
Dim CommandText As String
Dim rs As New ADODB.Recordset
Dim strMsg As String
Dim strText As String
Dim strFileText As String
Dim strHeaderText As String
Dim fs
Dim a
 
CommandText = "Exec QueryName '" & parameter& "'"
rs.Open CommandText, CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdText
  
If rs.RecordCount = 0 Then
  DoCmd.Hourglass False
  MsgBox "No Records to Export!"
  Exit Sub
  End If
 
strHeaderText = strHeaderText & """FieldName1""" & ","
strHeaderText = strHeaderText & """FieldName2"""
strFileText = strFileText & strHeaderText & vbCrLf
 
rs1.MoveFirst
 Do While Not rs.EOF
    strText = strText & """" & rs1 ("FieldName1") & """" & ","
    strText = strText & """" & rs1("FieldName2") & """"
    strFileText = strFileText & strText & vbCrLf
    strText = ""
    rs.MoveNext
 Loop
     
     Set fs = CreateObject("Scripting.FileSystemObject")
     Set a = fs.CreateTextFile(sPath & "\FileName.txt", True)
     a.WriteLine (strFileText)
     a.Close
     rs.Close
     Set rs = Nothing
Docmd.TransferSpreadSheet:
For this command also we changed the syntax accordingly.
 
In Access: 
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "QueryName", sFilename, True
 
Modified Code:
DoCmd.OutputTo acOutputServerView, _
 “ViewName ", acFormatXLS, sFilename, False
OR
DoCmd.OutputTo acOutputStoredProcedure, _
 "StoredProcedureName ParameterName", acFormatXLS, sFilename, False

Docmd.OpenForm Taking Parameter

Docmd.OpenForm taking input parameters was not supported in access ADP.  We had to convert the record source of the form to a view.  Only then did this command work.

DoCmd.OpenForm FormName, , , Condition

Print Functionality

In the print functionality we faced the problem of Header Record Delimiter Error.  For that, a header file with all the columns with appropriate delimiters had to be written.  We added the header file with “,” as field delimiter and “enter” as record delimiter and that solved our problem.

Updatable View

If the record source of a form is not an updatable view then one cannot edit any field of the form.  And the status bar always shows the error message “The Recordset is Not Updatable.”  Tables without unique index will be upsized, but they will be read-only in SQL Server.   We added a unique index to each of the tables used and made the required view updatable.  The view should not contain the following things to be updatable.

- A Set Operator (Union, Intersect, Minus, Union All)

- Distinct Operator

- Aggregate Functions (Sum, Avg, Count, etc.)

- A Group By Clause

- The select list with components other than column specification or more than one specification of the same column.

Error While Inserting Records to a Form

Sometimes when adding a record to an ADP form an error message appears:

“The data was added to the database but the data won't be displayed in the form because it doesn't satisfy the criteria in the underlying record source.”

For this we have to set the ResyncCommand Property of the Form in the design view to a SQL statement.

For Example: Resync Command: Select * From tblName where FieldName = ?

If the Rowsource contains a stored procedure with multiple tables joined together then the Resync Command Property of the form should be set to an SQL statement that selects the same fields as the stored procedure and parameterize the primary key of the table that is designated as the Unique Table.


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-19 12:55:50 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search