SqlProcedure does not exist in the namespace Microsoft.SqlServer.Server

Julia Zhuang 6 Reputation points

I am trying to create a CLR Stored Procedures assembly in visual studio following this tutorial: https://learn.microsoft.com/en-us/aspnet/web-forms/overview/data-access/advanced-data-access-scenarios/creating-stored-procedures-and-user-defined-functions-with-managed-code-cs
However, I have the error message saying SqlProcedure does not exist in the namespace Microsoft.SqlServer.Server.
I already have Microsoft.SqlServer.Server and System.Data.SqlClient imported using Nuget as shown in the picture, Can anyone help me with this error? Thanks!

Microsoft Technologies based on the .NET software framework.
3,140 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,224 questions
Visual Studio Setup
Visual Studio Setup
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Setup: The procedures involved in preparing a software program or application to operate within a computer or mobile device.
932 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Michael Taylor 43,891 Reputation points

    The SqlProcedureAttribute is defined in System.Data which should already be referenced by your code. It isn't defined in SMO and that assembly isn't needed unless you're trying to work with SMO for other reasons.

       using Microsoft.SqlServer.Server;  
       [SqlProcedure(Name = "MySproc")]  
       public static void MySproc ()  

    Based upon your solution explorer screenshot it looks like you might be trying to create a .NET 5/6 project for your code. Note that you won't be able to do that for SQL CLR. SQL CLR relies on the version of .NET that ships with SQL which is currently .NET Framework. Therefore you need to ensure that your code is compiling with a target framework of .NET 4.5 to 4.8, depending upon what version is actually installed on your SQL machine with 4.7.2 being the most common. Otherwise the code won't run.

    0 comments No comments