Search code examples
sql-serversql-server-2012sql-server-data-toolssqlclrsqlcmd

Deploying a CLR Assembly to a different database than the rest of the objects


I am using Visual Studio and a SQL Server Database Project to maintain my database objects through TFS. I have implemented a CLR Assembly for using RegEx Pattern matching in my UnitTests. I want to deploy this CLR to a different database than where the rest of the objects in the database would be deployed to.

  • Database_1 - contains all of the database objects
  • Database_2 - contains the CLR Assembly and UDFs for RegEx Pattern Matching.

I would like to create the script to deploy a CLR Assembly and related UDFs to one database, while creating the script which will deploy the rest of the changes to another database. I would like to do this using PRE/POST scripts using sqlcmd as I think this is the easiest way to do this.

Is this possible?


Solution

  • Publishing to another Database requires a different Database Project. They should be able to be in the same solution, but having two different Database projects will allow for different publishing properties (e.g. Target Database, etc).

    OR, a very quick and easy to not worry about any of that would be to use the SQL# SQLCLR library of functions (which I wrote). The free version of SQL# contains several RegEx functions as well as many others. You can just save the installation script (once the correct Database name has been edited into the USE statement) into TFS and be done with it :-).