Introduction
Welcome to the SQL-CLR For Beginners article series. In this article series, we discuss working with the SQL Server database component using C#. In the previous two articles, we saw how to create a simple Stored Procedure and triggers. If you are unfamiliar with them, please visit the following links.
- SQL CLR For Beginner: Part 1: Create Store Procedure in SQL-CLR Project
- SQL CLR For Beginner: Part 2: Create Trigger in SQL-CLR Project
This article will show how to create a simple function in a SQL-CLR Project. As we know, a function is a SQL Server (and in other databases, too) component. We can use them for calculation purposes or to execute a repeated job. In a few steps, let's see how to create a SQL Server function using the C# language.
Let's open Visual Studio 2010. Go to "File" -> "New" -> "Project...".

The "SQL Server" templates under the Database node are in the left-hand panel. Choose the "Visual C# SQL CLR Database Project" template. Provide your favorite name and select a location.

Once you click on the "Ok" button, it will pop up the following window and ask you to select a SQL Server database. You need to choose the database for this project.

Click the "Add New Reference" button, and a will pop up a window to configure your database connection. Select your server name and database name. After selection, ensure a connection can be established by pressing the "Test Connection" button.

Once you press "OK," the sample project structure will be created in the Solution Explorer section as in the following.









Muhammad MuazzamPosted Jun 20, 2018, 3:08 AM
How you can debug this program