I have a user defined data type in SQL Server 10 (2008):
CREATE TYPE [dbo].[sweyi047_corrid] FROM [binary](24) NULL
When this type is selected from a table I am unable to retrieve the data from .NET because I get an SqlException
at ExecuteReader
claiming that the type sweyi047_corrid
is unknown for parameter no. '1'. Trivial example:
var stmt = Connection.CreateCommand();
stmt.CommandText = @"CREATE TABLE #test ( col sweyi047_corrid );
INSERT INTO #test VALUES(0x1020);
SELECT col from #test";
var rdr = stmt.ExecuteReader(); // crash!
rdr.Read();
var ret = rdr.GetValue(0);
If I select only a scalar, everything works as expected for the same type:
stmt.CommandText = @"DECLARE @var sweyi047_corrid;
SET @var = 0x1020;
SELECT @var;";
In this case I get an object of type byte[24]
as expected.
How to read the tables containing UDT columns correctly?