Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft.SqlServer.Server namespace

I'm trying to implement a Common Language Runtime (CLR) assembly to use with SQL Server. For creating dll I'm using Visual Studio 2019.

I have the following code from an example tutorial:

using System;
using System.Collections;
using System.Text;
using System.Data;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;


namespace Split
{
    public class Class1
    {
        [SqlFunction(
            DataAccess = DataAccessKind.None,
            FillRowMethodName = "MyFillRowMethod"
            , IsDeterministic = true)
        ]

        public static IEnumerable Split(string stringToSplit, string delimiters)
        {

            string[] elements = stringToSplit.Split(delimiters.ToCharArray());
            return elements;
        }

        public static void MyFillRowMethod(Object theItem, out SqlChars results)
        {
            results = new SqlChars(theItem.ToString());
        }
    }
}

But I encounter this error:

Error CS0234 The type or namespace name 'SqlServer' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Can anybody show me the way of fixing my problem?

like image 362
Bohdan Avatar asked Aug 31 '19 15:08

Bohdan


People also ask

What is SQL Server namespace?

SqlServer. Server namespace, you can create stored procedures, triggers, user-defined types, user-defined functions (both scalar and table-valued), and user-defined aggregate functions in any supported . NET Framework language. You can also register them in SQL Server.

What namespace contains classes for connecting to Microsoft SQL Server?

Data. SqlClient. This assembly (namespace) of . NET Framework contains all of the classes required to connect to a SQL Server database and read, write, and update.

What is Microsoft SqlServer DAC?

SqlLocalDb.Dac. A library that makes it easy to do integration testing with SQL Server using a local DB. 13.0K. DbTestMonkey.Providers.SqlServer. SqlServer specific provider for DbTestMonkey.

Is Microsoft SqlServer free?

Microsoft SQL Server 2019 Express is a free, feature-rich editions of SQL Server that is ideal for learning, developing, powering desktop, web & small server applications, and for redistribution by ISVs.


Video Answer


1 Answers

As the error message hinted at:

You're probably missing the reference to System.Data.SqlClient, which contains the SqlFunctionAttribute in the Microsoft.SqlServer.Server namespace.

  1. Right click on your project and click on Manage NuGet Packages...

    NuGet

  2. Search for System.Data.SqlClient

    enter image description here

  3. Install

    enter image description here

That should resolve your issue.

like image 84
div Avatar answered Sep 23 '22 23:09

div