本文以Visual Studio 2008为例。
步骤:
1. 打开 Visual Studio 2008
2. New Project,选择 Visual C# –> Database –> SQL Server Project.
3. 设置 Project Name 为 MyClrProcTest,并点击 Ok.
4. 弹出对话框 “Add Database Reference”,找到并选中你的数据库然后确认.
5. 在 Solution Explorer 栏目中,右键点击 MyClrProcTest 工程-> Add –> Stored Procedure.
6. 弹出对话框 “Add New Item”,输入存储过程文件名为 sp_MyClrProc.cs,点 Add 确认.
7. 用以下代码替换:
using System; public partial class StoredProcedures param.Value = name; |
8. 编辑工程自动生成的SQL测试文件 Test.sql,在文件末添加一行
exec sp_MyClrProc @Name='Mike' |
9. 在运行上面的测试代码前先要启用 CLR 功能,在SQL Server Management Studio中运行如下命令:
sp_configure 'clr enabled', 1 |
10. 回到之前的工程 MyClrProc,按F5运行,观察输出内容
Greeting |
这样整个CLR存储过程就已经成功部署。