Here is my query, it is on 2014 Adventure works.
DECLARE @l_RunSQL VARCHAR(MAX);
SELECT @l_RunSQL = COALESCE(@l_RunSQL + ' UNION ALL SELECT * FROM [', 'SELECT * FROM [') + TABLE_SCHEMA +'].['+ TABLE_NAME+']'
FROM INFORMATION_SCHEMA.TABLES
WHERE [TABLE_TYPE] = 'BASE TABLE'
AND [TABLE_NAME] LIKE 'Address';
EXEC (@l_RunSQL)
WITH RESULT SETS
(
(
[AddressID] [INT],
[AddressLine1] [NVARCHAR](60),
[AddressLine2] [NVARCHAR](60),
[City] [NVARCHAR](30),
[StateProvinceID] [INT],
[PostalCode] [NVARCHAR](15),
[SpatialLocation] [GEOGRAPHY],
[rowguid] [UNIQUEIDENTIFIER],
[ModifiedDate] [DATETIME]
)
);
I am able to run this in SSMS and I get the contents of the Person.Address table as desired.
In C#, I create a connection node and then a command node and try and execute query like so:
using (var reader = command.ExecuteReader(CommandBehavior.SchemaOnly))
{
schemaTable = reader.GetSchemaTable();
}
And the reader results come back empty. Why is this command valid in SSMS but not using C# ?
The connection is of type System.Data.SqlClient.SqlConnection and the command is of type System.Data.SqlClient.SqlCommand.
Any help would be greatly appreciated