OLE DB data source in SSIS returning no records when using table variable

The other day I stumbled across a strange situation while working on a SSIS package. The package contained OLE DB datasource task using ‘SQL Command’ data access mode. This SQL command contained a table variable. My intention was to populate this table variable and then select data from it to be processed further in the package. After writing my query, I clicked preview and it nicely showed the rows I was looking for. However, when I executed the  package, no rows were returned. Bugger!!! The package wasn’t failing but it was not processing any records either. I checked the package configuration and ran the query in SSMS just to make sure the data is indeed there. Everything looked ok but still no records when the package is executed. Puzzled, I googled and came across the solution here. All credits to the original poster, I would recommend all to read it.

If you set SET NOCOUNT ON at the top of SQL Command, SQL Server will supress sending DONE_IN_PROC messages to the client. DONE_IN_PROC messages are  the messages you see in Messages Tab of query result window in SSMS. Setting SET NOCOUNT ON can also provide a significant performance boost as mentioned in the MSDN article here.

Intrigued, I decided to dig a little further. To begin, during package design, it seems that if there are multiple statements in SQL Command, OLE DB will pick up the metadata from the first SELECT statement. At package run time,I think, the first resultset is processed by OLE DB. When the SQL Command contained table variable and NOCOUNT is not set to ON, the DONE_IN_PROC messages are retruned as empty resultsets. OLE DB source takes the first resultset and proceeds further. Hence the package succeeds but no records are returned.

Of course, I might be completely wrong here but reading the OLE DB specifcations for solving a trivial issue doesn’t seem like a good idea. Any how, I atleast know the solution.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s