Question

I have created a CLR UDT for use with SQL Server 2008, and am now trying to actually use it from a database project.

  • Both the CLR UDT project and the database project are in the same solution in Visual Studio
  • Both are set to Deploy in the solution deployment settings
  • They are both configured in the respective project settings to deploy to the same database
  • I have added a reference and confirmed the resultant dependency from the database project to the CLR UDT project

Still, when I try to "Deploy Solution", it builds (note: does not deploy anywhere) the SQL CLR project, then starts going through "Validating the project model" of the database project and throws up with Error SQL03006: Column [schema].[table].[column] has an unresolved reference to Sql Type [typeschema].[typename]. on the database column where I use the CLR type.

I tried going into Tools -> Options -> Database Tools -> Schema Compare -> Microsoft SQL Server 2008 and under Object Types set it to ignore User-Defined Types (CLR), but this had no apparent effect whatsoever.

If I deploy the CLR UDT project to a database, go into that database and DECLARE a variable of that type through SQL Server Management Studio, that works (as expected). So this pretty clearly has something to do with Visual Studio's idea of model validity, rather than an actual problem with what could be the deployed result if it were only to try (and do things in the correct order).

Google was distinctly unhelpful. What am I missing?

Was it helpful?

Solution

I found the answer, and it was really simple when I realized what was going on but not quite so obvious before then.

What was needed was to add a CREATE TYPE command to an item creation script in the database project so that the CLR UDT becomes known as such to SQL Server. Visual Studio does this automatically on assembly deployment, but apparently does not consider it during database project model validation.

With CREATE TYPE in place, everything seems to be working as expected, and no error ignores are needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top