I am writing a SSIS package and trying to extract the data from one database to another. I have created a Execute SQL task and using the following statement INSERT INTO dbo.getParties EXEC dbo.getParties to perform the operation. This works when the source and destination our in the same database. How do I handle this when the source and destination are in different databases. You can associate only one connection manager to a task.
Do I connect to the source and in the SP call the destination. Is it the right way of doing it
Below is the design of my template
Use Data Flow component where you can set up the source and destination connection strings.
..and inside the data flow task use the Destination and Source Assistants that let you define its own connection string for each.
Of course, besides these you can also apply any sort of data transformations you wish.
Edit:
Since you your source is SQL Command (stored procedure) you need to define it in your source assistant. As you can see here, just change Data Access Mode to SQL Command and set to EXEC getParties:
In the Execute SQL Task INSERT INTO Command just add the Database name to the Table name. ex:
INSERT INTO Db1.dbo.Table1
SELECT * FROM Db2.dbo.Table2
Side Note: i think that it is better to use DataFlow Tasks to copy data, because it is faster and provides more controls and error handling
Related
Task:
Transfer data from SQL Server into Access Database
Issue:
How to empty my Access destination table before I run the data flow?
I tried to use an Execute SQL Task to run a TRUNCATE command similar to SQL Server, but it seems not working with Access Database?
Thanks in advance!
You can use Execute SQL Task to query a Microsoft Access Database, but you cannot use a Truncate command since it is not supported, you have to use a DELETE FROM ... command.
The following screenshots show an example of the OLE DB Connection manager, and the Execute SQL Task configuration:
I have made a SSIS package to transfer data between two databases on different server.
Now the issue is that i am unable to pass connection string in to package dynamically at run time.
i have a windows form to execute that package. On that Windows form i have drop downs to select source and destination Databases to transfer data.
so can i have a way to tell a package that this is the connection string of source and destination database where it needs to perform actions at running time, dynamically on click of windows form drop down clicks..
If the destination server will not change each time you can concatenate the server name in the ssis package connection string with variable, If not you need to pass the server name too form the Windows form.
In your package, right-click on the connection manager and select "Parametrize". Create paramenters for ServerName, InitialCatalog, UserName and Password. When executing the package, pass the parameters for the connection you want.
Alternatively, you can create one parameter for ConnectionString and pass that as a whole. I, personally, prefer the former.
I should add... this is for SSIS 2012 only. Package parameters didn't exist before then.
I have a folder with a .sql files; 1 file per query. I want to execute all queries/ sql files and save them as csv.
Is there a way to do that automated without using the windows cli (disabled in my environment). I do have the SQL Server Management Studio.
I would approach this task using SSIS, providing you have Business Intelligence Development Studio (BIDS) installed.
First create a 'Foreach Loop Container' pointed to the folder with the SQL files, then use a variable to retreive each file name.
Next, create a flat file connection and set the 'Connection String' property to the variable that contains the file location.
Next, using the 'Execute SQL Task' component set the 'SQLSourceType' to 'File Connection' and the 'FileConnection' to the one created in the previous step.
Finally, depending on how the data is returned you have a couple of options, if the result set is small, only a row or a single column, then you can save the results to a variable and using a 'Dataflow' task create a 'Derived Column' component and export the contents of that variable to a CSV file. Or, if the dataset is larger you could dump the results to a temp table and then using an 'OLE DB Source' and 'OLE DB Destination' you could push the full result set straight into a CSV.
Hopefully this isn't too convoluted of a solution, this approach has the advantage of being able be run from either a remote machine or from the server itself, plus you can automate its execution with a SQL Agent Job.
Create a VB.NET console application.
Generate a list of files that end in .SQL from the folder in question.
Load the contents of each file into individual SQL Commands
Execute the SQL Command for each, storing the results in DataSets.
For each table in each dataset, create a new .csv file
For each .csv file, you will need to iterate over each cell in the datatable, and utilize proper escaping for .csv files.
Use 'for' in combination with either sqlcmd or bcp command for each file in the script folder.
I use SQL Server Import and Export Wizard to transfer data from a remote server to my local server.
First step, Choose a Data Source.
Second step, Choose a Destination.
Third step, Specify Table Copy or Query, there are 2 options
I choose Write a query to specify the data to transfer because I need to organize the data on remote server first and then transfer the result.
Then I specify the SQL statement I want to run on remote server.
I found that the destination table name on my local server is forced to be 'Query'.
How can I change this from Query to something I specify?
On the screen after you select the query you get the 'Select Source Tables and Views' screen. On this screen you can select which table the data is written to in the destination column. This drop down will let you select any table in the destination database. So you will need to create your destination table in the destination database before using the wizard.
You can also edit column mappings and what happens to existing data by using the 'Edit Mappings...' button.
You are basically creating an ssis package via a wizard. Create the package manually, create a table destination variable, figure out a way to populate the table destination variable, and choose "Table or view name from variable" (choosing that variable) for the destination.
Is it possible to delete rows in an excel worksheet from SSIS?
From forum
create a file system task in control flow, deleting the file.
create a sql task, excel connection type, i used my previous excel connection for this, then used a create table script as my sql statement
left my previous export object the same, then linked the flow of these in this order described.
An arctile by microsoft claims that you cannot delete an entire row however you can delete a value in a cell. http://support.microsoft.com/kb/257819
This thread relates to someone with the same problem:
http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.adonet/2006-12/msg00245.html
In short, it seems like the answer is 'no', you cannot delete an entire row using ado.net via SSIS. You may be able to use excel automation or vb.net in excel itself to accomplish this task.
I also did it by following the steps suggested by Gulzar but, in case anyone wants the details, this is what I did:
I originally had a task to read some information from SQL Server and export it to Excel:
I then added the suggested tasks, one to delete the destination Excel file and one to recreate it:
This is the task to delete the file, it's a "File System Task":
This is the task to re-create the Excel file, it's an "Execute SQL Task":
The following needs to be set for this "Execute SQL Task":
a. Connection Type is "Excel"
b. As suggested, the connection is the same one used by the original Export task
c. The SQL statement was copied from the original Export task
That's basically it. Run it and it should work. My connection to SQL Server looks like this:
My Excel connection, which was originally created when the Export task was created, looks like this:
In the "Data Flow" section, using the Source Assistant, the original "OLE DB Source" has this:
And, using the Destination Assistant, the original Excel Destination has this:
This is the SQL Statement that I copied from the original Excel Destination: