Need to upload excel file using Script task in SSIS 2005. Can someone please help, provide the code.
Regards
I always use OLEDB for this and I answered this recently with a code sample here...
Best fastest way to read an excel sheet
I've always found it the best way, mainly because using a data flow task with an Excel Source doesn't allow you to either vary the Excel or to validate it's contents.
Related
I have a simple SSIS package. Extract data from database, load into an .xls file and then email to users using sp_send_dbmail task. I have few different reports I do this task for. Now the issue is that I need to add password to those files before sending to users. I can do this in two ways: password protect the template manually and load the file in SSIS OR load and password protect the file (both) in SSIS. SSIS has limitations where it cannot open protected file neither has any way to protect the file as a task. Here are the few ways I have research I can do this:
Excel Interop via Script Task: Upon a lot of research, I found its not the best practice as it causes a lot of server issues and requires licensing so i dropped this idea.
OpenXML via Script Task: It only works with .xlsx but I have .xls file and I can only use .xls
Excel Macros: I have created a Macro which perfectly protects a file but the issue arises on how to execute this. Upon research found out it can be executed using Interop.
Write a batch file that will execute Excel Macros: I haven't really found a solution on how to run them using batch file (if it is even possible)
Use PowerShell to protect the file and then execute them through Execute Process task in SSIS. I am not familiar with PowerShell but I have researching and saw it is possible.
I have done A LOT of research on it and I am unable to find a right solution. My knowledge is very limited to SQL. Any suggestion would be greatly appreciated, thanks!
Load the file normally then lock it using a powershell script or a macro (not sure if this is possible). Locking and unlocking are external to SSIS, so its best handled by some sort of scripting language such as powershell. Read this
Lock Unlock excel files using PS script
Is there a way to export data from a MS Excel file into a SQL Server table automatically? Maybe this is done using a script of some kind.
If it's not possible to be completely automated, perhaps there's a way to do it using minimal user effort. (For example clicking a button or link)
There is a MS Excel spreadsheet where the data keeps having to be manually exported to SQL Server.
I've done this using Excel to Access before, but not too certain on how to do it using SQL Server (MS).
*MS Office 2013 and MS SQL Server 2012.
The other answers are ok. I just want to suggest an additional alternative.
If it is just 1 specific Excel file that is frequently updated, I would consider using VBA. For example, write some VBA code in Excel that uploads changes to the database when the spreadsheet is saved (or the user presses a button).
The problem with using a scheduled job is that Excel is basically a single user application. If someone has the spreadsheet open or is doing something in it when the scheduled job runs or moves the spreadsheet to a different folder, then the job may fail.
This way you also get the updated data in your database in something close to real time instead of waiting on a job to run. This might take more time and effort to set up though than some of the other answers.
You can use SQL Server Agent to run a scheduled job that imports data from an Excel worksheet into a SQL Server table.
The import is relatively straightforward to do using Integration Services, but if you've not used either of these before you might need to do some reading up on it.
You can do the following:
You need to create an SSIS package and then create a job to run the package.
The easiest way to create the SSIS package is with "Import and Export Data" tool of SQL Server. It has a nice step by step wizard.
You set everything it asks you from the source and the destinations. Until you get here, select the "Save SSIS Package":
Then you only have to create the job to run it :)
I'm looking for a simple solution (beginner to SQL) to allow the import of data from my .csv file to my SQL DB.
I have a third party program that is updating my .csv file every 30 seconds and I want to put that updating information into my SQL DB. I tried the importing & exporting wizard but it didn't work due to the .csv file being utilized by the other third party program.
Getting the information into the SQL DB doesn't need to be in real time it could just retrieve all the information when opening a saved sql query file.
Thank you!
OPENROWSET is the simplest one if you get that working in your env for CSV file. i have seen lot of issues with what OS, and what version of MS office installed with 32bit or 64 bit.
but bit more work and you will be all set with creating a small SSIS package to import that CSV in to table. execute that SSIS using SQL JOB at desired interval. later if you needed more complex insert/update you can always modify the package.
This is the case of producer consumer problem where one process is writing data and another one is reading it.
Whatever you do you need to setup some kind of lock on this file that process can check if file is available for reading/writing. If import/export wizard had issues with concurrency then probably other processes will also.
Another option is to always create new file to write into and have reader process to always read from the newest one and delete it after processing.
One more thing you’ll have to take care of is reading from same file multiple times. You need some way to mark the records that have already been read so these are not inserted twice.
All of the above is needed if this needs to be a fully automated and unattended process.
If not you can just manually create a copy of CSV file and then use import/export wizard to import the data.
Here is another resource you can check out for importing CSV into SQL Server
http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/
I have an SQL database with records of different library members. At the end of the month, I need to print out a sheet with all members who haven't returned their library books and their addresses. I am okay with the query, but I don't know how to print out the results on a paper in tabular form? Is there a proper way of doing this?
I was thinking of writing the results to an html document and printing that. Would that be a good idea? Thanks for your help.
Hiya hope link below help; :
[links] - with code
1) Export to excel - export from sql server to excel file using asp.net and vb.net?
2) Crystal report - http://vb.net-informations.com/crystal-report/crystal_report_from_sql_query_string.htm
hope its helps, if you want you can share what you have done, I can try and fix your code. Cheers!
You could use Crystal Reports, an extension that shipped with VB6: http://www.vb6.us/tutorials/using-crystal-reports-vb6-tutorial
Or a very crude way would be to create an MS Excel file rather than an HTML file as it would give you much more structure control along with an excellent editor post generation.
You can use Word mailmerge with ODBC databases to create directories ( http://support.microsoft.com/kb/294693 ). A HTML document also sounds quite useful.
I have developed a program in which all data is entered into a SQL DB. the program has been designed in Visual Studio using Visual Basic. I am now getting external data supplied in an excel format and need to know how to import the excel data into the SQL DB and ensure the data goes into the appropriate columns. I have set a template up for them with standard excel headers and I open and view the data into a datagridview before the import but the last part which is the import function to SQL I have not yet worked out.
Any help would be most appreciative.
Is there a specific problem that you're having?
A better bet might be to use SSIS to import the data. It's what SSIS is made to do.