There comes a time in every SQL Server dba’s life when they will have to consolidate an MS Access database to an SQL Server. It’s inevitable and destiny decided that it was my turn today. A heavily used Access database which had almost grown beyond its capacity sealed my fate. It had about 1.2 GB of data and had become extremely slow at executing queries, which was something we could no longer ignore. This was the first Access database I was going to migrate, so I started by doing some research on the good old internet. Many people suggest that making SSIS packages is the easiest way to do this, while others recommend using openrowset or opendatasource. I chose the openrowset technique.
First of all I listed all the Access tables and stored them in a table on my SQL Server, so that I could use this table to loop through all my tables on the Access database using openrowset.
Let’s get started.
I found the following connection string for openrowset online and tried it but instantly got my first error:
SELECT * FROM OPENROWSET(‘Microsoft.ACE.OLEDB.12.0’, ‘MYPATH\Access.mdb’;’Username’;’Password’;’SELECT * FROM Tablename’);
Msg 7403, Level 16, State 1, Line 1 The OLE DB provider “Microsoft.ACE.OLEDB.12.0” has not been registered.
This one is fairly straightforward – I can’t use OLEDB for Access because I haven’t installed it yet. So I installed the provider and reran the statement and this time I got the following error:
Msg 7438, Level 16, State 1, Line 1 The 32-bit OLE DB provider “Microsoft.ACE.OLEDB.12.0″ cannot be loaded in-process on a 64-bit SQL Server.
Oops, made another mistake. I’m using a 64-bit SQL Server but this doesn’t work with a 32-bit provider. So then I had to uninstall it and reinstall the 64-bit driver. You can find this here.
After installing the provider I got the statement to work.
Next I created a loop to execute the openrowset query for all my tables. To use a parameter in the openrowset query I had to put the whole statement into a variable and execute it with exec:
declare @table varchar(400)
DECLARE TableList CURSOR FOR
select name from dbo.tables
DECLARE @CMD varchar(4000)
OPEN TableList
FETCH NEXT FROM TableList
INTO @table
WHILE @@FETCH_STATUS = 0
BEGIN
SET @CMD =’ select * from OPENROWSET(”Microsoft.ACE.OLEDB.12.0”,”C:\Atoum\databases\atoum_data_fixed.mdb”;”someuser”;”somepassword”,”select * from ‘+@table+”’)’
exec (@CMD)
FETCH NEXT FROM TableList
INTO @table
END
CLOSE TableList;
DEALLOCATE TableList;
This worked perfectly.
Now I could get all this table data but I still had to insert it into a table, preferably with the same name & structure as in Access. I did this by using select * into from:
declare @table varchar(400)
DECLARE TableList CURSOR FOR
select name from dbo.tables
DECLARE @CMD varchar(4000)
OPEN TableList
FETCH NEXT FROM TableList
INTO @table
WHILE @@FETCH_STATUS = 0
BEGIN
SET @CMD = ‘ select * into ‘+@table+’ from OPENROWSET(”Microsoft.ACE.OLEDB.12.0”,”C:\Atoum\atoum_data_fixed.mdb”;”someuser”;”somepassword”;”select * from ‘+@table+”’)’
exec (@CMD)
FETCH NEXT FROM TableList
INTO @table
END
CLOSE TableList;
DEALLOCATE TableList;
Note: After this step you still need to look at your column sizes and expand some of them, e.g. description fields. You also have to create primary and foreign keys as they were created in the Access database to ensure data integrity, and create clustered & nonclustered indexes for performance.
This created all the tables in a loop, with the right number of columns & data types, and inserted the data directly into them. So after executing this statement, the Access to SQL Server migration was a success. That is how I tackled the issue of migrating an Access database to SQL Server. There are different ways of doing this for different situations and you will have to decide what is best for you… when your inevitable Access migration comes along.
© 2023 Kohera
Crafted by
© 2022 Kohera
Crafted by
Cookie | Duration | Description |
---|---|---|
ARRAffinity | session | ARRAffinity cookie is set by Azure app service, and allows the service to choose the right instance established by a user to deliver subsequent requests made by that user. |
ARRAffinitySameSite | session | This cookie is set by Windows Azure cloud, and is used for load balancing to make sure the visitor page requests are routed to the same server in any browsing session. |
cookielawinfo-checkbox-advertisement | 1 year | Set by the GDPR Cookie Consent plugin, this cookie records the user consent for the cookies in the "Advertisement" category. |
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
CookieLawInfoConsent | 1 year | CookieYes sets this cookie to record the default button state of the corresponding category and the status of CCPA. It works only in coordination with the primary cookie. |
elementor | never | The website's WordPress theme uses this cookie. It allows the website owner to implement or change the website's content in real-time. |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
Cookie | Duration | Description |
---|---|---|
__cf_bm | 30 minutes | Cloudflare set the cookie to support Cloudflare Bot Management. |
pll_language | 1 year | Polylang sets this cookie to remember the language the user selects when returning to the website and get the language information when unavailable in another way. |
Cookie | Duration | Description |
---|---|---|
_ga | 1 year 1 month 4 days | Google Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors. |
_ga_* | 1 year 1 month 4 days | Google Analytics sets this cookie to store and count page views. |
_gat_gtag_UA_* | 1 minute | Google Analytics sets this cookie to store a unique user ID. |
_gid | 1 day | Google Analytics sets this cookie to store information on how visitors use a website while also creating an analytics report of the website's performance. Some of the collected data includes the number of visitors, their source, and the pages they visit anonymously. |
ai_session | 30 minutes | This is a unique anonymous session identifier cookie set by Microsoft Application Insights software to gather statistical usage and telemetry data for apps built on the Azure cloud platform. |
CONSENT | 2 years | YouTube sets this cookie via embedded YouTube videos and registers anonymous statistical data. |
vuid | 1 year 1 month 4 days | Vimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. |
Cookie | Duration | Description |
---|---|---|
ai_user | 1 year | Microsoft Azure sets this cookie as a unique user identifier cookie, enabling counting of the number of users accessing the application over time. |
VISITOR_INFO1_LIVE | 5 months 27 days | YouTube sets this cookie to measure bandwidth, determining whether the user gets the new or old player interface. |
YSC | session | Youtube sets this cookie to track the views of embedded videos on Youtube pages. |
yt-remote-connected-devices | never | YouTube sets this cookie to store the user's video preferences using embedded YouTube videos. |
yt-remote-device-id | never | YouTube sets this cookie to store the user's video preferences using embedded YouTube videos. |
yt.innertube::nextId | never | YouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen. |
yt.innertube::requests | never | YouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen. |
Cookie | Duration | Description |
---|---|---|
WFESessionId | session | No description available. |