Introduction
Welcome to the SQL-CLR For Beginners article series. In our previous three articles, we have seen how to execute basic Stored Procedures, Triggers, and Functions in SQL-CLR Applications. If you are unfamiliar with them, please visit the following links.
This article will teach us how to use a traditional C# class within a SQL-CLR Application. To do that, first, we need to create one SQL-CLR application. Use the following screens and see how to do it.
Select "File" -> "New" -> "Project...".

In the templates on the left, select "Installed Templates" -> "Database" -> "SQL Server." From the project types in the middle, select the "Visual C# SQL CLR Database Project" template, and provide a nice name and path to save it to.

Once you click "OK," it will ask you to select a database server. Choose the SQL Server where the application is to be deployed. It might be a remote server or your local server. Once you have established a connection, it will show you the following connection success message.

Go to the Test Script folder. Right-click, then select "Add" -> "Class." Once you press "OK," it will create an empty template for the SQL-CLR project.

Choose "Class" and give it a nice name. In my case, it's "ClsPerson."

In this example, we will create a simple Person class called "ClsPerson." Once you press "OK," it will create an empty class for you. And a note is that it's nothing but our very familiar C# class. It has three properties.
The following is the structure of the class.
We will now add a Stored Procedure to this project. Right-click on "Test Scripts," then select "Add" -> "Stored Procedure."
![SQLCLR6.jpg]()
Select the Stored Procedure and provide a name. Here we used "Classconsumer".
![SQLCLR7.jpg]()
This is the default body of the Stored Procedure. Yes, it is nothing but one more C# class. Here we are not doing any helpful operation within the Stored Procedure. For example, we create an object of the person class; then, after assigning a few properties, we supply them to the Stored Procedure to display a pipe. This pipe is for sending data from the C# CLR code to the SQL Server object.
We need to do one helpful task; we will change the target .NET Framework version from 4.0 to 3.5.
![SQLCLR8.jpg]()
Then, right-click on Solution Explorer and click on "Deploy." Once it is deployed successfully, you will get the successful message.
![SQLCLR9.jpg]()
Now go to SQL Server Management Studio, and select your chosen database. Type "EXEC ClassConsumer" and run it. For the first time, what you had chosen.
![SQLCLR10.jpg]()
I hope the screen you see is very similar to the preceding one.
Conclusion
This is the fourth article of the series SQL CLR For Beginners: Create Store Procedure in SQL-CLR Project.
For reading the next articles of this series, Please go through these links-