Microsoft.SqlServer.Server 1.0.0

Prefix Reserved
dotnet add package Microsoft.SqlServer.Server --version 1.0.0
                    
NuGet\Install-Package Microsoft.SqlServer.Server -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.SqlServer.Server" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Microsoft.SqlServer.Server" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Microsoft.SqlServer.Server" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Microsoft.SqlServer.Server --version 1.0.0
                    
#r "nuget: Microsoft.SqlServer.Server, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Microsoft.SqlServer.Server@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Microsoft.SqlServer.Server&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Microsoft.SqlServer.Server&version=1.0.0
                    
Install as a Cake Tool

Microsoft.SqlServer.Server

NuGet NuGet Downloads

Description

This is a helper library for Microsoft.Data.SqlClient, enabling cross-framework support for User-Defined Types (UDTs) in SQL Server.

The package provides the types and attributes needed to create SQL Server CLR user-defined types, user-defined aggregates, and user-defined functions that work seamlessly across .NET Framework and .NET Core/.NET.

Supportability

This package supports:

  • .NET Framework 4.6+
  • .NET Standard 2.0 (for .NET Core 2.0+ and .NET 5+)

Installation

Install the package via NuGet:

dotnet add package Microsoft.SqlServer.Server

Or via the Package Manager Console:

Install-Package Microsoft.SqlServer.Server

Available Types

This package provides the following types in the Microsoft.SqlServer.Server namespace:

Type Description
IBinarySerialize Interface for custom binary serialization of UDTs
InvalidUdtException Exception thrown when a UDT is invalid
SqlFacetAttribute Specifies additional information about UDT properties
SqlFunctionAttribute Marks a method as a SQL Server function
SqlMethodAttribute Specifies method properties for UDT methods
SqlUserDefinedAggregateAttribute Marks a class as a user-defined aggregate
SqlUserDefinedTypeAttribute Marks a class as a user-defined type
DataAccessKind Describes data access behavior for a function
SystemDataAccessKind Describes system data access behavior
Format Specifies the serialization format for UDTs

Getting Started

Creating a User-Defined Type

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

[SqlUserDefinedType(Format.Native)]
public struct Point : INullable
{
    private bool _isNull;
    private double _x;
    private double _y;

    public bool IsNull => _isNull;

    public static Point Null
    {
        get
        {
            var p = new Point();
            p._isNull = true;
            return p;
        }
    }

    public double X
    {
        get => _x;
        set => _x = value;
    }

    public double Y
    {
        get => _y;
        set => _y = value;
    }

    public static Point Parse(SqlString s)
    {
        if (s.IsNull)
            return Null;
        
        var parts = s.Value.Split(',');
        return new Point
        {
            X = double.Parse(parts[0]),
            Y = double.Parse(parts[1])
        };
    }

    public override string ToString() => _isNull ? "NULL" : $"{_x},{_y}";
}

Creating a User-Defined Aggregate

using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
using System.IO;

[SqlUserDefinedAggregate(Format.UserDefined, MaxByteSize = 8000)]
public class Concatenate : IBinarySerialize
{
    private StringBuilder _builder;

    public void Init()
    {
        _builder = new StringBuilder();
    }

    public void Accumulate(SqlString value)
    {
        if (!value.IsNull)
        {
            if (_builder.Length > 0)
                _builder.Append(",");
            _builder.Append(value.Value);
        }
    }

    public void Merge(Concatenate other)
    {
        if (other._builder.Length > 0)
        {
            if (_builder.Length > 0)
                _builder.Append(",");
            _builder.Append(other._builder);
        }
    }

    public SqlString Terminate() => new SqlString(_builder.ToString());

    public void Read(BinaryReader reader) => _builder = new StringBuilder(reader.ReadString());
    public void Write(BinaryWriter writer) => writer.Write(_builder.ToString());
}

Documentation

Release Notes

Release notes are available at: https://go.microsoft.com/fwlink/?linkid=2185441

License

This package is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Microsoft.SqlServer.Server:

Repository Stars
microsoft/DacFx
DacFx, SqlPackage, and other SQL development libraries enable declarative database development and database portability across SQL versions and environments. Share feedback here on dacpacs, bacpacs, and SQL projects.
MyCaffe/MyCaffe
A complete deep learning platform written almost entirely in C# for Windows developers! Now you can write your own layers in C#!
Version Downloads Last Updated
1.0.0 6 3/12/2026