Mar 17, 2013

Import Images to Sql Server using SSIS

In this article, I am going to demonstrate step by step to create a package in SQL Server Integration Services (SSIS) to import Images in SQL Server.

Step 1: Create a Flat File named ListImages.txt containing list of paths of images to be imported in SQL Server

Content of ListImages.txt
C:\Images\Image1.gif
C:\Images\Image2.gif

Step 2: Create a Table to store Images in SQL Server Database
CREATE TABLE dbo.tblImages(
    id int IDENTITY(1,1) NOT NULL PRIMARY KEY
    , imgPath varchar(200) NULL
    , image image NULL
 )

Step 3: Run SQL Server Business Intelligence Studio and create a New SQL Server Integration Project ImportImages. This will open Control Flow Task Tab by default


Step 4: Drag and drop the Data Flow Task from the Toolbox to the Control Flow Task.


Step 5: In the design pane Right Click on Data Flow Task and then click Edit or Double Click the Data Flow Task. This will open Data Flow Task Tab.


Step 6: From the Toolbox drag and drop following components on Data Flow Task Tab
  • Flat File Source
  • Import Column
  • OLE DB Destination. 
Join the components with the green arrows as shown below.


Step 7: Right Click on Flat File Source and then click Edit.


Step 8: In the Flat File Connection Manager, press New.


Step 9: In the General Option, mention
  • Connection Manager Name
  • Description (Optional) 
  • Browse Flat File ListImages.txt created in Step 1.

Step 10: Select Advance option and change the name to ImagePath. Click OK twice to save the settings.


Step 11: Right Click on Import Column and then click Edit. In the new window, select Input Columns Tab and Select Name


Step 12: Select Input and Output Properties Tab and expand Import Column Output from the TreeView. Select Output Columns and click on Add Column. Get the ID property value of the column created. (In this example, ID is 58)


Step 13: Expand Import Column Input from the TreeView and select ImagePath. In Column Properties, set FileDataColumnID value to 58 (generated in step 12) and Click Ok to save the settings


Step 14: Right Click on OLE DB Destination and then click Edit


Step 15: In the OLE DB Destination Editor Window, press New for the OLE DB connection manager.


Step 16:. In the Configure OLE DB Connection Manager press New...


Step 17: In the Connection Manager, select Native OLE DB\SQL Server Native Client as provider and provide other details like Server Name, Authentication Type, Credentials and Database Name to connect to SQL Server Database and Click Ok.


Step 18: In the OLE DB Destination Editor Window, In Connection Manager Option select the table tblImages.


Step 19: Select Mapping Option and do the mapping as shown below and Click Ok.


Step 20: At this point, we are done with creating the package and ready to run the project. If everything is OK, all the tasks should be displayed with green color and the number of rows imported should be displayed.


Step 21: To verify the data is imported successfully, Open SQL Server Management Studio and connect the database and open the table tblImages


    Choose :
  • OR
  • To comment
4 comments:
Write Comments
  1. its good but i am getting error in OLE DB Destination "Truncation may occur due to inserting data from data flow column "Image Path" with a length of 255..."

    ReplyDelete
    Replies
    1. I believe the size of actual image path would be greater than the size of column "ImagePath" in database table. Please increase the size of "Imagepath" in the table and try once again.

      Delete
  2. Yes later i found that my notepad was empty. Now it is solved...really nice post..

    ReplyDelete