How to Upload a Zip File to My Server

Introduction

I have seen many organizations receive data from diverse sources and import into SQL Server. Yous might receive data in various formats and want to import into SQL Server. We can set a ETL (Extract-Transform-Load) process to import data into the SQL Server. In doing and so, might receive data in a compressed file, which helps to send information over the network using a Nil file format because it reduces the file size significantly. If nosotros are receiving a Nada file to import into SQL Server, nosotros demand to unzip information technology and then only we tin import data. We might need to create a Null file as well from the existing files.

Overview

In this article, nosotros will showtime look out the following tasks

  • Ready a compressed file using an SSIS package
  • Unzip files using SSIS bundle
  • Import data into SQL Server tables using a ZIP file

Step-by-step

We have the following excel file, and we want to ZIP the file using the SSIS parcel.

SQL import of compressed data: Sample Microsoft Excel file to use in SSIS package

Nosotros need to exercise the following steps to Nil this file:

Nosotros need to open up Visual Studio 2017 with SQL Server Data Tools to prepare the SSIS packet. If we do have it installed, you can go to Install SSDT with Visual Studio 2017 and download required setup files. We demand to install SQL Server Integration Services feature during the installation.

SQL import of compressed data: Launch shortcut of Visual Studio 2017 (SSDT)

In Visual Studio 2017, go to File -> New -> Projection.

SQL import of compressed data: Create new project in Visual Studio 2017

It opens the new projection wizard. In Business Intelligence templates, click on Integration Services and Integration Service Project.

SQL import of compressed data: Create new Integration Service Project in Visual Studio 2017

Every bit shown in the epitome above, we can provide the SSIS package name and location to create the SSIS package solution. It creates a solution in the directory.

SQL import of compressed data: SSIS Solution in the directory

In the Control Menstruum, drag Execute Process Job in SSIS configuration.

SQL import of compressed data: Execute Process Task in SSIS package

Right click on the Execute Procedure Task and Rename information technology to File Zilch Job.

SQL import of compressed data: Execute Process Task in SSIS package

We can run across renamed task in the following epitome.

SQL import of compressed data: Rename the Execute Process Task

It opens the Execute Process Task Editor.

SQL import of compressed data: Execute Process Task Editor

In this article, we are going to use the open up source tool with compression to prepare the compressed files into the .7z extension. It is available with the Windows past default. Yous can find this utility in C:\Program Files\7-Zippo directory.

SQL import of compressed data: Compression Utility 7z.exe in Windows environment

In the Execute Procedure Task Editor, click on Procedure.

SQL import of compressed data: Execute Process Task Editor

In the Executable, we demand to specify the path for the 7z.exe. You can browse to the directory or paste the consummate path here as shown in the following prototype.

SQL import of compressed data: Execute Process Task Editor configuration

In the Arguments, nosotros need to blazon post-obit control.

a -t7z "C:\sqlshack\Typhoon articles\Data\Inventory.zip" "C:\sqlshack\Draft articles\Data\Inventory.xlsx"

Let me explain these arguments.

  • A – This argument specifies a file to add to the archive
  • t7z – It specifies the archive type. In this article, we want to create a t7z annal file
  • Destination zip filename and directory: In the next statement, specify the Zip file proper noun along with the absolute path that we desire to create
  • Source file path and file name: In the last argument, we need to specify the absolute file path for the file we want to ZIP

In the Working directory, we can specify the directory for 7z executable file.

SQL import of compressed data: Execute Process Task Editor configuration

Click OK, and Nosotros tin see that File ZIP Task is ready to execute.

SQL import of compressed data: File ZIP Task to prepare a compress file

Press F5 or click on the Commencement to run this File ZIP Task. Information technology opens a command prompt with the 7z.exe pinch utility. Yous can encounter the Nada file progress status as well in this command prompt. You lot might non notice this command prompt if file size is small.

SQL import of compressed data: Compression using 7z.exe in SSIS package

We tin see a green tick icon on File Naught Task one time it is successfully executed.

SQL import of compressed data: Success message of the File ZIP Task

Click on Progress, and you can see progress message of the File ZIP task.

SQL import of compressed data: Monitor Progress of SSIS package

Now permit us go to the destination path that we specified in argument. In the following prototype, you lot can see Inventory.nil file for the excel file. You lot tin notice the size difference besides.

  • Microsoft Excel file size: five,192 KB (Without compression)
  • Compressed files size: 582 KB

SQL import of compressed data: View and compare the properties of compressed file

Now let u.s.a. place two files in the same folder.

SQL import of compressed data: Add sample file to do compression using SSIS task

Nosotros want to create a Zilch file containing both the files in information technology. We do not need to create two Nada task in the SSIS packet. Open the File Nada Task in the SSIS package nosotros created earlier. We can specify the below statement. In this argument, we specified the source file paths 'C:\sqlshack\Draft articles\Data\*.*"' . It takes all the files in the source path and zips them into a single file.

a -t7z "C:\sqlshack\Draft manufactures\Information\CompressDemo.nix" "C:\sqlshack\Draft manufactures\Data\*.*"

SQL import of compressed data: Execute Process Task Editor configuration

Now execute the package over again. In the command prompt window, we tin can see information technology is adding 2 files into an archive.

SQL import of compressed data: Compress multiple files using SSIS package

Let the states go to the destination path, and you tin see a unmarried compressed file.

SQL import of compressed data: Verify the compress file created using SSIS package

For the verification purpose, right click on the compressed ZIP file and extract the file using the option Extract to 'CompressDemo\'

SQL import of compressed data: Extract compress file for verification

Nosotros can see both the files in the extracted file as shown below.

SQL import of compressed data: Verify the files created after extraction

Extract files using the SSIS Package

We take explored the process to create a compressed file using a SSIS package. Suppose we received a Zilch file to import into SQL Server tabular array. This ZIP file contains an Excel file. We cannot import data from a Aught file directly into SQL Server. We demand to extract the file first and then import the excel file into SQL Server and extract the files into a different folder using the SSIS package only.

We have the post-obit Goose egg file into our source path.

SQL import of compressed data: Sample compressed file

Now let us create the SSIS package into ii steps.

  1. Unzip the file
  2. Import the file into the SQL Server.

We tin can unzip a file using the execute process task. Rename the execute procedure task equally File Unzip Task.

SQL import of compressed data: File Unzip Task in SSIS package

Double click on File Unzip Task and in the argument, we need to specify the argument for extract the ZIP file.

e "C:\sqlshack\Draft articles\Data\Inventory.zip"

In this argument, e instructs to extract the files.

Information technology extracts files in the working directory folder. Let us execute this task to see if Unzip is working fine or not. Information technology unzips the files very quickly. Yous might non notice the extract process since it completes in a fraction of second. It might take longer if the compressed file size is enormous.

SQL import of compressed data: Extract files using the 7z.exe in SSIS package

In the Visual Studio, nosotros tin see that File Unzip task is also completed successfully.

SQL import of compressed data: Monitor success of the SSIS task

Let get to the working directory binder, and as per the following screenshot, we can see the extracted file is present here.

SQL import of compressed data: Verify the extracted file

Import compressed file data into SQL Server

Nosotros desire to load data from Zippo file into SQL Server tabular array, therefore, add a Data Flow Task and connect it with the File Unzip Task.

SQL import of compressed data: Data Flow Task in SSIS Package

Rename Information Flow Task to Import Excel into SQL Server.

SQL import of compressed data: Rename the data flow task

Double click on the Import Excel into SQL Server. It opens data flow page in which nosotros demand to ascertain the source and destination connections.

SQL import of compressed data: Configure the excel source in SSIS package

In the Excel Source, specify the excel file path. This path should be the working directory in Unzip File Task.

SQL import of compressed data: Configure the excel source in SSIS package

Click Ok and specify the sheet name.

Importing compressed data into SQL Server: Configure the excel source in SSIS package

We tin can view these columns from the right side bill of fare option Columns.

Importing compressed data into SQL Server: verify the mapping between External and Output column

Click Ok, and we tin can see Excel source in the post-obit prototype.

Importing compressed data into SQL Server: Verify the Excel Source in SSIS package

Now add an OLE DB destination and connect information technology to the Excel Source.

Importing compressed data into SQL Server: Add an OLE DB destination

We need to configure the OLE DB Destination now. Double click on this destination and we demand to specify the OLE DB connection manager. If we do not accept the existing connection, click on New and specify the destination connexion manager.

Importing compressed data into SQL Server: OLE DB Connection Manager

If we have a tabular array already present, we can select tabular array from the driblet-down list. If destination table does not be, click on New in front of Name of the table or the view. It automatically shows script to create the destination table with valid information types.

Importing compressed data into SQL Server: Create table in the SSIS package

Specify table name as per the requirement.

Importing compressed data into SQL Server: Create table in the SSIS package

Click OK, and we can run across that tabular array as highlighted in the post-obit screenshot.

Importing compressed data into SQL Server: Select the table name from the drop-down list

Now click on Mappings to practise the mapping betwixt source and destination. Information technology automatically creates mapping; however, we tin change mapping if required.

Importing compressed data into SQL Server: Verify the mapping between Input and Destination Column

Click OK, and we tin run into the configured data menstruation job.

Importing compressed data into SQL Server: Verify the configured data flow task

Salvage the package and verify that the source binder contains the Nix file.

We can see the below configured to Control Flow task.

Importing compressed data into SQL Server: Verify Control Flow task

Allow u.s. execute this packet at present. We can track each task status in Visual Studio.

Importing compressed data into SQL Server: Monitor progress of SSIS package

We tin can run across that FileUnZip Chore is completed successfully. We tin can verify this from the working directory. Nosotros take the unzipped file every bit shown in the following image.

Verify the uncompressed file

We can see that the parcel is executed successfully.

Importing compressed data into SQL Server: View the status of SSIS package tasks

Let us go to the SQL Server table in which we imported information from a compressed excel file.

In the following screenshot, we can see that the number of records is 1046801. It shows that nosotros take successfully imported information using the compressed excel file into the SQL Server tabular array.

Conclusion

In this article, we explored the style to import data from a compressed file into SQL Server tables. It provides u.s.a. with flexibility, avoids manual task for unzipping the file, and then imports it. In the adjacent article, nosotros volition explore the apply of Python for importing Zero file data into SQL Server.

Table of contents

  • Writer
  • Contempo Posts

Rajendra Gupta

jonesangroys.blogspot.com

Source: https://www.sqlshack.com/importing-data-into-sql-server-from-compressed-files/

0 Response to "How to Upload a Zip File to My Server"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel