SSIS package creates tables on the wrong database - sql-server

This issue occurred and I would like to know possible causes:
During text file import the SSIS package created tables in the wrong database instead of writing in the correct tables in the correct database.
Details: There is an application which uses SSIS packages to import text files daily.
Those file records are stored in tables in the application database and they are available until the next set of files is received, when the new records will replace them.
The records are also stored in another database where they are kept, with import date information.
The tables keeping the same information in the two databases have different names.
The SSIS package contains:
two database connections
a file connection
and a dataflow task with:
- one flat file Source
- one multicast
- two OLE DB destinations
Execution: dtexec
The package has been running for a year now.
There is NO table creation task.
I connect the output of the multicast to already created tables in the database.
Issue: one time the SSIS package wrote the records in the storage database tables and, instead of writing in the application database tables, it created the application database tables in the storage database and wrote the records there.
What could have caused it?
Thanks in advance.

Related

Exporting column records from .CSV to multiple table in SQL Server using SSIS

I have a requirement to create a batch solution using SSIS package.
I am new to SSIS hence exploring this to implement my scenario.
Scenario:
An external system will dump data into .CSV file on weekly basis on
specific directory on server.
An SSIS package will be scheduled to run on weekly basis to read
that .CSV file path on server and write those data in multiple table
in SQL Server.
Task:
The source .CSV file with set of columns belong to different tables in SQL Server. Those column and data in that row should be mapped to specific columns in different tables.
My thought to ask community -
What alternatives SSIS provides which allows me to segregate each
column in .CSV file and map them to different table in SQL Server?
In .CSV I have eleven columns. As per SQL table structure, those
eleven columns are distributed into four separate tables.
I appreciate any productive advise to implement the solution.
UPDATE: Below things so far I setup/tried
I created new SSI package successfully. In Data flow so far as a
source I setup the variables to read path and file name.
I setup OLE DB datasource as destination and establish connection to
server.
I believe I have reached by completing setup with .CSV as a source
to read columns, but I am still exploring what would be ideal
destination or how OLE DB would help to consume records in different
tables.
I went through Multicast and Import Columns options. I
understand that the Multicast is mainly used to share or output
data to different destinations.
you can create four OLE DB destinations and using multicast you can route your data.
so basically multicast will pass all the 11 tables to all four destinations and there you can map only required column with your tables.
Let me know if you have any confusion.

create reusable controls/packages in an one dtsx package in SSIS?

We use SSIS for our data automation. The caveat is we don't use the normal way mentioned online. For our environment, we save the Package.dtsx file on a server that has a windows job that will execute it using dtexec.exe.
I have multiple SSIS packages to pull data from various sources (Oracle, MySQL, SQL Server) and the general flow for them is the same. The table names are different but I will use data as the table names for one of the sources/SSIS packages.
backup the table data into bak_data on the destination DB
import new data from the source into data
compare data quality (row count) against data and bak_data
if data quality does meet our threshold, send a success e-mail (execute task against our destination DB using db_send_dbmail)
if the data quality does not meet our threshold, backup data to bad_data then restore from bak_data to data and send failure e-mail
Since the steps are always the same I thought I could use Control Flow Package Parts and then just use variables for the table names and what not.
But upon further investigation I realized I cannot do that because the Control Flow Package .dtsxp is a separate file referenced in/from the Package.dtsx file?
I can copy it to our automation server but not sure if that will be enough to work when Package.dtsx is executed using dtexec.
Is there anyway I can create reusable controls/packages with my constraint/situation?

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/

Copy data from one table and save it into another table in different database on different SQL Server

I have two different databases in two different SQL Servers. The databases are identical in schema but contain different data in one of the tables.
I want to copy all the data from one table in one database to the same table in the other database so that I can get rid of the database from which I am copying the data.
The data is too large so I cannot create data scripts and run it onto other database.
How can I achieve this?
There are many ways like ssis transfer,select * into ,but i prefer below way if you are just transferring data
create a linked server on source server for destination server,then you could refer destination server with four part name
Assuming linked server of source is A and destination server is B,data moving is as simple as
insert into B.databasename.Schema.Table
select * from table---this is in source server and db
if data is huge and you may worry about time outs,you can write a simple script which can do in batches like
While (1=1)
begin
insert into B.databasename.Schema.Table
select top 10000* from table---this is in source server and db
if (##rowcount=0)
break
end
Creating linked server ,you can follow this
You have the following options available to you. Not all of these will work, depending on your exact requirements and the networking arrangements between the servers.
SQL Server Management Studio - Import & Export Wizard: this is accessed from the right-click menu for a database > Tasks > Import Data (or Export Data).
SQL query using a Linked Server: a Linked Server configured between the two servers allows you to reference databases on one from the other, in much the same way as if they were on the same server. Any valid SQL query approach for transferring data between two tables within one database will then work, provided you fully-qualify the table names as Server.Database.Schema.Table.
SSIS: create an SSIS package with both servers as connections, and a simple workflow to move the data from one to the other. There is plenty of information available online on how to use SSIS.
Export to flat-file format then import: this could be done using the Import/Export Wizard above or SSIS, but instead of piping the data directly between the two servers, you would output the data from the source table into a suitable flat-file format on the filesystem. CSV is the most commonly used format for this. This file can then be moved to the destination server using any file transfer approach (compressed e.g. to a Zip file if desired), and imported into the destination table.
Database backup and restore: Similar to (4), but instead of using a flat file, you could create a backup of the source database via Tasks > Back Up... You then move that backup as a file (just like the CSV approach), and restore it onto the destination server. Now you have two databases on the destination server, and can move data from one to the other locally.
I hope, this query helps you!!!
INSERT INTO [dbo].[tablename] (Column1, Column2,Column3)
(select Column1, Column2,Column3, from [Database1].[dbo].[tablename]
Thanks!!!

SSIS Transfer Task That Handles Schema Changes

I'm using SSIS with SQL Server 2k5 to build a transfer task to copy all of the data from one database to another. This works quite well, except for one problem - the source database will periodically have schema changes (generally just additions like new columns) but the transfer task seems to choke if the two schemas don't match exactly. Is there some way that I can use SSIS to first bring the target DB up to date with the source DB's schema, and then do the transfer?
You can open the package programmatically and re-save it before executing. You can also programmatically build the package using the SSIS object model.

Resources