简体   繁体   中英

How do I import MS Access data into SQL Server using SSIS package?

I've spend the better part of a day looking around for anything to help me, but SSIS is such a huge tool that nothing is of any use so far, or maybe I just don't understand it.

I need to take an old Access db that has some problems and move it into SQL server. I already have the schema set up in my SQL db. The old data needs to be fixed up, things like normalization and removing duplicates. My boss insists on using SSIS for this job, because we need someone here who knows how to use it, and currently almost no one does (one manager used it a long time ago).

So, I have a project set up in BDIS, or visual studio, or whatever this app actually is. I created a connection manager to my Access db, and I managed to drag an OLE DB Source onto the designer and set it up to connect to that db. I also figured out that I can select data from there.

Now what? I'd really prefer to have a way to just write a giant SQL script to grab all the data I need from the Access db, transform it how I want, and shove it into the SQL server database. But it looks like I'll need to use all these funky transformation tools in the designer. I also can't figure out how I'll get the resulting data into SQL server. I have the connection set up in the Server Explorer pane, but everyone online says never use the SQL Server Destination. So I'm lost there as well.

My boss said the Books Online help files would be very useful. So far, it's been like finding a needle in a haystack submerged under a swamp, with three castles sitting on top of it. There's just too much information, and none of it seems useful to me.

Edit

Hopefully some more information will be useful. I think the wizards that come with SSIS aren't powerful enough for what I want, so if they are, you'll have to please explain it. Here's an example of what I have to do, except my reality is a lot more tables with more transformations.

Say I have a source table that looks like this:

Companies
====================================================
| Name    | Address    | WidgetOne   | WidgetTwo   |
|--------------------------------------------------|
| ACME    | 123 etc.   | Trampoline  | Cannon      |
====================================================

I need to normalize this into two tables. And it will obviously have to track the IDs so that the widgets are associated with the correct company. If you could help with an example of how this case would be handled with SSIS , from Access to SQL server, then I can probably take it from there. Thanks!

Following example probably might give you an idea to perform data migration from MS Access to SQL Server. The example uses MS Access 2010 and SQL Server 2008 R2 database. The package was written in SSIS 2008 R2 . Unlike the previously provided solution, This answer doesn't use the SQL Server Import and Export Wizard and the package was built from ground-up.

Step-by-step process:

  1. Let's assume that the Access table is as shown in screenshot # 1 with a table named Companies containing two rows in a de-normalized fashion.

  2. And also assuming that the table structure in SQL Server is as shown in screenshots # 2 and # 3 with two tables named dbo.CompanyInfo and dbo.WidgetInfo . Create table scripts are provided under SQL Scripts section. The tables are empty as shown in screenshot # 4 .

  3. Create a new SSIS package. On the SSIS package, right-click on the connection manager and select New OLE DB Connection as shown in screenshot # 5 . On the Configure OLE DB Connection Manager, click New... button as shown in screenshot # 6 .

  4. On the Connection Manager, select Native OLE DB/Microsoft Jet 4.0 OLE DB Provider and provide the Access file path. In this example, I have the file in C:\temp\Source.mdb . Click OK. Refer screenshot # 7 . On the Configure OLE DB Connection Manager, click OK as shown in screenshot # 8 . Change the connection manager name to AccessDB (the name could be anything of your preference). Refer screenshot # 9 .

  5. Again, right-click on the Connection manager and select New OLE DB Connection as shown in screenshot # 10 . This time we are going to create a connection string for SQL Server. Select Native OLE DB\SQL Server Native Client 10.0 and provide the Server name and database name as shown in screenshot # 11 . Rename the connection manager to SQLServer (again, name is your choice). Refer screenshot # 12 .

  6. On the SSIS package's Control Flow tab, place a Data Flow Task and name it as Populate CompanyInfo . Double-click on the data flow task to switch to the Data Flow tab. Within the Data Flow Task, place an OLE DB Source , a Derived Transformation and an OLE DB Destination as shown in screenshot # 13 . NOTE: You need to configure the tasks one by one in the order shown. Don't place all the tasks at the same time and try to connect them.

  7. Configure the OLE DB source to read the Access database table as shown in screenshots # 14 and # 15 . Configure the Derived transformation to convert the string text from Access database to Unicode as shown in screenshot # 16 . Configure the OLE DB Destination to insert the data into SQL table as shown in screenshots # 17 and # 18 .

  8. Go back to Control Flow tab and place another Data Flow Task as shown in screenshot # 19 .

  9. In the second data flow task, we read the same Companies table in Access database and try to populate the WidgetInfo table in SQL.

  10. Place an OLE DB Source to read the Access table and configure it as hown in screenshots # 20 and # 21 . Place a Derived transformation to convert the string to Unicode as shown in screenshot # 22 . Place a Lookup transformation to fetch the CompanyId based on the name and address and configure the task as shown in screenshots # 23 and # 24 . Lookup task by default will fail if it can't find a match. We need to normalize the Widget data. So, place an Unpivot transformation and configure it as shown in screenshot # 25 . Place an OLE DB Destination to insert the data into SQL and configure it as shown in screenshots # 26 and # 27 . Second data flow task would be as shown in screenshot # 28

  11. Screenshots # 29 - # 31 show sample package execution.

  12. Screenshot # 32 shows data in the SQL tables after the package execution.

I hope that this should give an idea of exporting data from Access database to SQL server. You can group the tables in Access and load them within a single data flow task. If there are tables depending on other tables, then you can place the in separate data flow task as demonstrated in this example.

Hope that helps.

SQL Scripts:

CREATE TABLE [dbo].[CompanyInfo](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [CompanyName] [nvarchar](80) NOT NULL,
    [CompanyAddress] [nvarchar](255) NOT NULL,
CONSTRAINT [PK_CompanyInfo] PRIMARY KEY CLUSTERED ([Id] ASC)) ON [PRIMARY]
GO

CREATE TABLE [dbo].[WidgetInfo](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [CompanyId] [int] NOT NULL,
    [WidgetName] [nvarchar](40) NOT NULL,
CONSTRAINT [PK_WidgetInfo] PRIMARY KEY CLUSTERED ([Id] ASC)) ON [PRIMARY]
GO

Screenshot #1:

1

Screenshot #2:

2

Screenshot #3:

3

Screenshot #4:

4

Screenshot #5:

5

Screenshot #6:

6

Screenshot #7:

7

Screenshot #8:

8

Screenshot #9:

9

Screenshot #10:

10

Screenshot #11:

11

Screenshot #12:

12

Screenshot #13:

13

Screenshot #14:

14

Screenshot #15:

15

Screenshot #16:

16

Screenshot #17:

17

Screenshot #18:

18

Screenshot #19:

19

Screenshot #20:

20

Screenshot #21:

21

Screenshot #22:

22

Screenshot #23:

23

Screenshot #24:

24

Screenshot #25:

25

Screenshot #26:

26

Screenshot #27:

27

Screenshot #28:

28

Screenshot #29:

29

Screenshot #30:

30

Screenshot #31:

31

Screenshot #32:

32

This might help:

  1. You'll need connection2 to you source and desination database. It sounds like you already have your source.

  2. You'll need a data flow task in the 'Control Flow' tab. Drag one of these on and double cli ck - you'll be taken to the 'data flow' tab.

  3. here add a 'data source' (which it sounds like you have done) and also add an 'OLE DB Destination'.

  4. Double-click your source. You shoud be able to specify the connection (again it looks like you've done that),

  5. 'Data Access Mode' specifes how you want to retrieve the data. Ie straight from a table, or write a query that returns the data

  6. if it is a straight one-one mapping to the destination, you should be able to connect the two with a the green line (a precidence constraint).

If you want to do any transformations then you can do so in the query on the soruce, or put one of the transformation obejcts in between the source and destination and connect them accoringly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM