How to manually deploy SQL Server CLR assembly

Source: Internet
Author: User

The following is the process of manually deploying the SQL Server CLR assembly. Here, we will make a record for you to read it at any time and provide reference for those who have no manual deployment experience, if you have any more convenient and intelligent methods, thank you!

Previously, deploying SQL Server CLR assembly with VS was simple and easy. Now the server is deployed on the Intranet, and you must manually update and deploy SQL Server CLR assembly.

Start to think of alter assembly [ASSEMBLY name] FROM 'G: \ AA \ XX. in this way, the dll is OK. I didn't expect an error and the more complicated it is to query the information. It seems that the manual deployment is far less as simple as I think, so I did a good research and finally succeeded. The specific steps are as follows:

1. If you have previously deployed the current Assembly, you must first delete all modules that reference the current Assembly (various functions and stored procedures) and then delete the current Assembly.

2. redeploy the current Assembly, and then create relevant modules (various functions and stored procedures ).

The following is an SQL template. You can set it as needed:

 
 
  1. -- ====================================== Delete first ====== ===================================== --
  2. -- MyCLRSqlserver indicates the Assembly deployment name.
  3. If exists (SELECT * FROM sys. assemblies asms WHERE asms. name = n' MyCLRSqlserver 'and is_user_defined = 1)
  4. BEGIN
  5. -- Delete a set function.
  6. If exists (SELECT * FROM sys. objects WHERE object_id = OBJECT_ID (n' [dbo]. [StrJoin] ') AND type = n' AF ')
  7. Drop aggregate dbo. StrJoin;
  8. -- Delete a scalar function.
  9. If exists (SELECT * FROM sys. objects WHERE object_id = OBJECT_ID (n' [dbo]. [___ fun_CLR_ChangeSalarieScope] ') AND type in (n'fn', n'if', n'tf', n'fs', n'ft '))
  10. Drop function dbo. ___ fun_clr_changesalari.pdf;
  11. -- Delete other...
  12. -- Uninstall the assembly.
  13. Drop assembly [MyCLRSqlserver];
  14. END;
  15. -- ==================================== Recreate ===================================== --
  16. -- Register the Assembly (if it is deployed on the server, copy the dll to the server and modify the file address ).
  17. Create assembly [MyCLRSqlserver] FROM 'G: \ AA \ XX. dll ';
  18. -------------------- [Dbo]. [StrJoin] ----------------------
  19. Create aggregate [dbo]. [StrJoin]
  20. (@ Value [nvarchar] (4000 ))
  21. RETURNS [nvarchar] (4000)
  22. External name [MyCLRSqlserver]. [MyCLRSqlserver. StrJoin]
  23. GO
  24. EXEC sys. sp_addextendedproperty @ name = n' autodeployed', @ value = n' yes ', @ level0type = n' SCHEMA', @ level0name = n' dbo ', @ level1type = n' aggregate', @ level1name = n' strjoin'
  25. GO
  26. EXEC sys. sp_addextendedproperty @ name = n' sqlassemblyfile', @ value = n' StrJoin. cs ', @ level0type = n' SCHEMA', @ level0name = n' dbo', @ level1type = n' aggregate', @ level1name = n' strjoin'
  27. GO
  28. EXEC sys. sp_addextendedproperty @ name = n' SqlAssemblyFileLine ', @ value = 14, @ level0type = n' SCHEMA', @ level0name = n' dbo', @ level1type = n' aggregate ', @ level1name = n' strjoin'
  29. GO
  30. -- Other function creation processes...
  31. -- ===================================================== ===================================== --

The above is a difficult manual creation process. Of course, if there are not many modules, this is okay. If there are many, you can check the system view of the current database assembly_modules to obtain all CLR modules, then write the code to automatically generate the DROP and CREATE processes for the module.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.