select data from excel spreadsheet that's read only - sql-server

I've got a dtsx package that selects data from an excel spreadsheet on the network and inserts it into a sql server table twice a day. However, the process fails if someone is in the spreadsheet modifying data. Is there a way to select data from an excel spreadsheet so that it doesn't fail if someone is in the spreadsheet?

Not used dtsx in anger in a long time but as an alternative solution.
Each time the job runs, would it be possible to create a temporary copy of that spreasheet (via your dtsx package) and then you can use that copy instead to import the data into table. When your done with the copy you can simply remove it.

Related

How to implement this specific action in my SSIS package?

I have created an SSIS package for my database running on SQL Server 2014.
This SSIS package extracts data from an Excel workbook (residing in a shared folder on my Windows Server) and feeds a table in my database. I have tested the package (through a SQL Job) and it works fine.
The logic behind the creation of this package is to pull data on a daily basis from that Excel workbook (the latter being updated on a daily basis). It does have a date column; so, data updated are tagged with the relevant date.
Since this SQL job will be executed on a daily basis, the table will be filled with duplicates (that is, data from Day 1 will be repeated on Day 2 and so on).
How can I deal this issue? I was thinking on adding a T-SQL flow to my SSIS package to delete the contents of the Table before it pulls the data from the Excel Workbook. I guess this would work but I am on the look out for a more elegant solution.
Any help would be appreciated.

SSIS Importing Excel Data

I've been tasked with importing data from an excel spreadsheet in to a table in SQL 2012. The spreadsheet will have data added to it monthly.
My plan, is to use SSIS to create a workflow to do this, I then will use SQL Job agent to execute the workflow at the beginning of every month to add in the new data.
One problem i can think of with this plan is the spreadsheet is going to become huge and eventually exceed the excel maximum rows. Instead of adding to the one spreadsheet I could have a new spreadsheet for each month? Though I'm not sure how I can use the workflow to pick the newest spreadsheet to add to the table
I'm a complete novice to SSIS, there might even be a more practical way of doing this whole process, so please feel free to offer suggestions.
Why inserting data into one Excel worksheet??
Inserting data into one Excel worksheet or even one workbook (Excel file) is not a good practice at all, you have to think in another way, you can create a new Excel file each time new data comes and save historical data in another repository or directory (if you need to). Or as #TabAlleman suggested if you can use flat files, it is more recommended since reading data from Excel is more difficult. But also make sure that you will not store all data in one flat file.

SSIS: Truncate Excel Destination

I am creating a SSIS package that imporr data from a SQL Server Source to an Excel Destination.
How can one truncate spreadsheet before run?
I tried the following way (using Execute SQL Task with no success.
Jet provider does not support neither truncate or delete command. You have 3 workarounds:
Have an empty excel template that you clone before the running the dataflow, or
Use execute sql task to create a new workbook/tab before running the dataflow
Drop the worksheet using Drop Table TableCall_Log and create a new one. You can referer to this Link for more details.
Useful Links
Deleting Records in an Excel Sheet using SSIS
Import Header-Line tables into Dynamic Excel destinations II
SSIS: Dynamically Generate Excel Table/Sheet
Truncation is not supported. You can recreate the whole excel file using two tasks:
The first task will be File task which deletes destination xls file.
The second task will be Execute SQL Task, which creates "table" (excel sheet). Use EXCEL connection type with excel connection manager and CREATE TABLE statement.
If you do not know the exact form of CREATE TABLE statement, then try to first prepare excel destination in a data flow task and by creating new excel sheet (by pushing New button on Connection Manager tab in Excel Destination editor) SSIS designer will show you CREATE TABLE statement which you need.
Connect the first task to the second task using Completion constraint if you are not sure, that the excel file exists every time you run the package.
You may also need to set DelayedValidation property to True on tasks following these first two tasks.

Update SQL Server (2014) table from an Excel email attachment

We track IPs that attack our site. First attack, we temp block them. Tf they ever attack again then we permanently blacklist them. Information for each attack by each IP is stored in perpetuum. Twice daily, reports with an Excel spreadsheet with all pertinent information is emailed to various people, and then the information is manually added to a massive spreadsheet. We've recently spun up a new box with SQL server and I've added all of the existing information to a table in the new database.
As I'm new to this, I would like to know if there is a way to send the daily spreadsheets to this new sql server and have it parse out the excel attachment and update our master tracking table. The spreadsheet will always have the same structure (15 columns and header and footer rows) with varying row quantities, and of course it matches the existing table structure.
I've been googling it and am only able to find queries (ba dum tish) on how to make SQL export to excel and send an email with Database Mail. Can't find anything on sending en email TO sql server and having it process an attachment.
You can make use of the SQL Server Integration Services(SSIS). You can write an SSIS package that import the data from the given Excel spreadsheet to a table and
then from that table you can write insert or update statements to your production table. You can use "Data Flow task" to Import the Data from the excel file and then write an " Execute SQL Task" which will update the values to Production table. Remember that you will have to keep the Excel file in the same folder all time (or else you can use dynamic statements to get the file name dynamically using Variables). Once you have completed the package you can schedule the package as an SQL Server Job which will run periodically and hence the data will be automatically updated.
Please refer this video for a basic idea about SSIS :
Import Data From Excel to SQL Server Using SSIS
Twice daily, reports with an Excel spreadsheet with all pertinent information is emailed to various people,
Try saving the File to a location and then use SSMS Export,Import Wizard ..This package can be saved and set to Run Daily
Here is a step by step tutorial covering the same..
https://www.mssqltips.com/sqlservertutorial/203/simple-way-to-import-data-into-sql-server/

SSIS Export to Excel Succeeds Once Only

I've created an SSIS package with the purpose of deleting and then recreating an Excel sheet, and then inserting data from a SQL database into that Excel sheet.
What I currenty have is:
1.) An Execute SQL task to delete 'Sheet1' from a local Excel file.
2.) An Execute SQL task to recreate 'Sheet1' in the same Excel file.
3.) A Data Flow task that uses an OLE DB Source to a 2005 SQL Server database.
4.) An Excel Destinaton (using an Excel Connection Manager) which points at / maps the SQL Server columns to the local Excel spreadsheet.
So essentially I'm deleting the Excel Sheet to remove old data, recreating it, and then trying to import the SQL data into it.
This worked well when I ran it the first time. When I try to rerun it however, all the tasks run successfully, the correct number of rows are shown to move to the Excel destination on the data flow tab, but the Excel spreadsheets are blank.
Can anyone suggest why this might be happening?
Thanks, Gavin
Is this the only sheet in your Excel file? If so, it might be easier to use the File System Task component to delete the entire file before creating your sheet (and therefore file) in your Execute SQL statement.

Resources