Run procedure in SSIS with temp table - ssis

I have procedure that contains two parts:
1- I have a select to insert data into temporary table
2- I have this to export to csv.
On SSIS when I try ti run this procedure I got this error
Is any way to solve this?

ssis creates a new connection per component. For this reason, in the execution of the second code, it does not have access to the temp table.
To solve this problem, there are two solutions:
Use two sharp ##Export_Table in creating the temp table (global temporary table).
In ssis, change the retainSameConnection option to true in the connection properties window

Related

I don't use temp table in SSIS

I have problem when I used OLE-DB Source temp table in SSIS.
I create temp table in Execute T-SQL Statement Task and I change DelayValidation : True and RetainSameConnection : True . But problem is not solved .
Background
What's likely happening here is that the table does not exist at the moment. Temporary tables come in two variants: local and global.
A local temporary table, uses a name with a single sharp/pound/hash/octothorpe prepended to it i.e. #TEMP. The only query that can use that instance of the temporary table is the one that creates it. This is why the advice across the internet says you need to set RetainSameConnection to true to ensure the connection that created the table is reused in the data flow. Otherwise, you're at the mercy of connection pooling and maybe the same connection is used in both places, maybe not and believe me that's an unpleasant bit of randomness to try and debug. The reason for the DelayValidation on the data flow is that as the package starts, the engine will validate that all the data looks as expected before it does any work. As the precursor step is what gets the data flow task into the expected state, we need to tell the execution to only validate the task immediately before execution. Validation always happens, it's just a matter of when you pay the price.
A global temporary table is defined with a double sharp/etc sign prepended to it, ##TEMP. This is accessible by any process, not just the connection that created it. It will live until the creating connection goes away (or explicitly drops it).
Resolution
Once the package is designed (the metadata is established in the data flow), using local temporary table is going to work just fine. Developing it though, it's impossible to use a local temporary table as a source in the data flow. If you execute the precursor step, that connection will open up, create the temporary table and then the connection goes away as does the temporary table.
I would resolve this by the following steps
Copy the query in your Execute SQL Task into a window in SSMS and create your local temporary table as a global temporary table, thus ##TEMP.
Create an SSIS variable called SourceQuery of type String with a value of SELECT * FROM ##TEMP;
Modify the "Data access mode" from the OLE DB Source from "SQL Command" to "SQL Command from Variable" and use the variable User::SourceQuery
Complete the design of the Data Flow
Save the package to ensure the metadata is persisted
Change the query in our variable from referencing ##TEMP to #TEMP
Save again.
Drop the ##TEMP table or close the connection
Run the package to ensure everything is working as I expect it.
Steps 2, 3, and 6 in the above allows you to emulate the magician pulling the tablecloth out from underneath all the dishes.
If you were to manually edit the query in the data flow itself from ##TEMP to #TEMP, the validation fires and since there is no #TEMP table available, it'll report VS_NEEDSNEWMETADATA and likely doesn't let you save the package. Using a variable as the query source provides a level of indirection that gets us around the "validate-on-change"/reinitialize metadata step.

SSIS - Use SSIS to Create SQL Table, Load Data, Run Code and Drop Table

I am kinda new to SSIS and apologize in advance if this is a repeat post, or simply a dumb question.
I am trying to create the following process in SSIS:
1- [SQL Execute Task] Create Table in SQL DB
2- [Data Flow Task] Load Data from a source file (.xls) into the Created SQL table
3- [SQL Execute Task] Run Code on Created SQL table
4- [SQL Execute Task] Drop the SQL table that was created
The problem I am running into is when I set my OLE DB Destination it wants a table that is already created. I tried to create the table and then run the process, it works the first time, but errors the 2nd time saying the table doesnt exist, even though it is skipping step 1 of creating the table.
Any ideas on a work around, or am I missing something very obvious here?
Thanks in advance!
So first, why drop the table every time? Your package is going to require consistent metadata for the table, so why not just truncate it and save it for the next load? This is a really kind of terrible approach to SSIS packages.
The reason it's failing is because SSIS does both design-time and runtime validation of all your components, so all it sees is the table's not there that it expects to be there.
But if your heart's set on this approach, you need to set the ValidateExternalMetadata property of your destination component to false. As long as the External Columns on the component match the actual columns being generated by your CREATE TABLE statement, you'll be good to go.

temporary table in SSIS ado.net source

I can only find a solution for using temp table in OLE DB source.
But I can't find a solution for ADO.NET source. How can I successfully use temp table in the ADo.NET source in SSIS package?
I find working with temporary tables in SSIS more pain than they are usually worth. I hope your experience is better.
Create an ADO.NET connection. In the properties of the Connection Manager set the value of RetainSameConnection from false to true. This will allow the temporary table created to be in existence for the duration of the package execution by preventing connection pooling from swapping out threads.
My trouble extends from getting the metadata set up correctly. To get around this, I create a variable, QuerySource, that queries a physical table that mirrors what the temporary table will look like. SELECT S.src_id, S.src_value FROM dbo.SRC AS S; This allows the data flow to establish the correct meta data for the downstream components. I manually use this query in the ADO.NET source. Once that's done, I will need to change the query to use the temporary table, ##SRC. Unlike the OLE DB Source component, you cannot set this property inside the Data Flow task.
Once the data flow work is completed, back in the Control Flow, view the Properties of the Data Flow Task. Change the Delay Validation from false to true. This will prevent any design time validation from firing which is needed once we remove the non-temporary table "scaffolding." Next find the Expressions and click the ellipses (...). In the drop down, you should see the name of your ADO.NET source. I had renamed mine so I saw [ADONET Src].[TableOrViewName] and [ADONET Src].[SqlCommand] in the drop down list. I selected [ADONET Src].[SqlCommand] and as my value, I used #[User::SrcQuery].
I ran the package to ensure it still worked. It did. I then changed the value of my query to be SELECT S.src_id, S.src_value FROM ##SRC AS S; I reran and this time it correctly pulled data from my temporary table.
If you are using SQL Server 2012 as your source, you might be able to make it easier on yourself by using the WITH RESULT SETS option of the EXECUTE statement to explicitly describe your temporary tables metadata.

Use temp tables in SSIS packages

I am writing a basic file dump from one database to another. I am using SSIS 2008 and creating several packages to transform the data I have from a MSSQL 2010 database to a MYSQL 5.1 database.
All the connections are set up and records can be tranfered between the two databases but I would like to use temp tables in the transform processes and use the temp table as the MSSQL source in a dataflow task to dump the table in an awaiting MYSQL table.
I have been having problems setting this up. I am using an OLEDB connection and have set the RetainSameConnection property as well as the DelayValidation property to true. When setting up the source figure as the source from the MSSQL database I cannot find the temp table I have created in an earlier task from the control flow. I am using the same connection manager for these two tasks.
Anyone have any ideas or experience with this?
As a simple example one task does..
SELECT *
INTO #TMP
FROM CUSTOMERS
(This is a simplified example and I relize in this case I could just use the Customers table so bear with me)
Is it possible to use this temp table in a dataflow operation as the source table?
As I mentioned in my comment, not much of a solution and more of a workaround. SSIS uses the shape of result sets to bind properties in tasks. As temp tables are not always available in the database this can cause errors in SSIS even if you set DelayValidation to true.
My solution is to create an SSIS schema in whichever database you're connecting to. The reasons for doing so are security and clear separation of objects that are only used within SSIS packages - primarily staging tables.
Instead of throwing tables in your dbo schema (you shouldn't be anyway, shame on you) you'd create them in the SSIS schema. A typical data flow would truncate the table when it begins, load values and perform whatever operations are required, optionally truncating it when complete. As long as the table is always available SSIS can examine the shape of result sets.
You should not use temp tables as the source as it will not recognize the columns for the select. use table variables or CTEs instead.

How to create a temporary table in SSIS with an identity column and a dynamic seed value

When an SSIS tasks runs, I want to create a temporary table with an identity column. However the seed for this column should start with a value = Select max(columnname_from_another_table) + 1.
I know SQL but not SSIS. One method I know is create the table and then issue something like 'DBCC CHECKIDENT('TempTable', RESEED, #TheCalculatedSeedValue) but I am not sure how to put all this together in SSIS.
SSIS has what are called SQL Tasks. This enables you to execute any T-SQL you want. You can have as many SQL Tasks as you want in an SSIS package. This should do what you want.