Microsoft Edge Try Microsoft Edge A fast and secure browser that's designed for Windows 10 Get started

Skip to main content
Microsoft
Microsoft Support
  • Office
  • Windows
  • Surface
  • Xbox
  • Deals
  • Support
      • Windows apps
      • OneDrive
      • Outlook
      • Skype
      • OneNote
      • PCs & tablets
      • Accessories
      • Xbox games
      • PC games
      • Windows digital games
      • Microsoft Azure
      • Microsoft Dynamics 365
      • Microsoft 365
      • Cloud platform
      • Enterprise solutions
      • Data platform
      • .NET
      • Visual Studio
      • Windows Dev Center
      • Docs
      • Free downloads & security
      • Education
      • Gift cards
    • View all
    0
    Sign in
    Microsoft Support

    FIX: A system assert occurs when a Transact-SQL stored procedure with a TVP argument is called from a SQLCLR procedure

    Content provided by Microsoft

    Content provided by Microsoft

    Applies to: SQL Server 2014 DeveloperSQL Server 2014 EnterpriseSQL Server 2014 Enterprise CoreSQL Server 2014 StandardSQL Server 2016 DeveloperSQL Server 2016 EnterpriseSQL Server 2016 Enterprise CoreSQL Server 2016 StandardMicrosoft SQL Server 2016 Service Pack 1 More


    Symptoms


    Assume that you have a Transact-SQL stored procedure such as the following that takes a table-valued parameter (TVP) that has a constraint as an argument:

    create typeTestTvpType as table   

    (

      id int primary key, --UNIQUE will also do the trick

      data int

    ); 

    go 

    create procedureTestTvpProc @tvp TestTvpType readonly

    as

    begin

      select * from @tvp;

    end;

    go

    In a scenario where this procedure is called from a SQLCLR stored procedure and the constraint is violated for the argument, you may incorrectly receive a system assert, when you would expect to receive a "constraint violation" error message.

    The following is an example of a SQLCLR procedure producing a constraint violation for the stored procedure:

    [SqlProcedure]

    public static voidClrProcCallingTsqlProcWithTvpArgument(out int sum)

    {

           using (SqlConnectionconnection = new SqlConnection("contextconnection=true"))

           {

                  sum = 0;

                  DataTablemyDataTable = new DataTable("TestTvpType");

                  myDataTable.Columns.Add("id", typeof(Int32));

                  myDataTable.Columns.Add("data", typeof(Int32));

                  //Populate the TVP so it will trigger a PRIMARY KEY VIOLATION error

                  myDataTable.Rows.Add(1,1000);

                  myDataTable.Rows.Add(1,2000);

                  SqlParameterparameter = new SqlParameter();

                  parameter.ParameterName= "@tvp";

                  parameter.SqlDbType= System.Data.SqlDbType.Structured;

                  parameter.Value= myDataTable;

                  SqlCommandcommand = new SqlCommand("TestTvpProc",connection);

                  command.CommandType= CommandType.StoredProcedure;

                  command.Parameters.Add(parameter);

                  connection.Open();

                  using(SqlDataReader reader = command.ExecuteReader())

                  {

                         while(reader.Read())

                         {

                               …;

                         }

                  }

           }

    }

    Resolution


    This issue is fixed in the following cumulative updates for SQL Server:
     
         Cumulative Update 5 for SQL Server 2016 RTM
     
         Cumulative Update 2 for SQL Server 2016 SP1
     
         Cumulative Update 4 for SQL Server 2014 Service Pack 2
     
    Note This update causes the return of the correct "constraint violation" error message.
     
    About cumulative updates for SQL Server

    Each new cumulative update for SQL Server contains all the hotfixes and security fixes that were included in the previous cumulative update. Check out the latest cumulative updates for SQL Server:

    Latest cumulative update for SQL Server 2016

    Latest cumulative updates for SQL Server 2014

    Status


    Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

     

    References


    Learn about the terminology Microsoft uses to describe software updates.


    Last Updated: 20 Mar 2017
    • Email
    • Print
    Thanks! Your feedback will help us improve the support experience.

    Support

    Support

    • Find downloads
    • Account support
    • Supported products list
    • Microsoft Lifecycle Policy

    Security

    Security

    • Safety & Security Center
    • Download Security Essentials
    • Malicious Software Removal Tool

    Contact us

    Contact us

    • Report a support scam
    • Contact Microsoft Support
    • Privacy questions
    • Locate Microsoft addresses worldwide
    This site in other countries/regions
    Algérie - Français
    Argentina - Español
    Australia - English
    Belgique - Français
    België - Nederlands
    Bolivia - Español
    Bosna i Hercegovina - Hrvatski
    Brasil - Português
    Canada - English
    Canada - Français
    Chile - Español
    Colombia - Español
    Costa Rica - Español
    Crna Gora - Srpski
    Danmark - Dansk
    Deutschland - Deutsch
    Dominican Republic - Español
    Ecuador - Español
    Eesti - Eesti
    El Salvador - Español
    España - Español
    Estados Unidos - Español
    France - Français
    Guatemala - Español
    Hong Kong SAR - English
    Hrvatska - Hrvatski
    India - English
    Indonesia (Bahasa) - Bahasa
    Ireland - English
    Italia - Italiano
    Latvija - Latviešu
    Lietuva - Lietuvių
    Luxembourg - Français
    Magyarország - Magyar
    Malaysia - English
    Maroc - Français
    México - Español
    Nederland - Nederlands
    New Zealand - English
    Norge - Bokmål
    Panamá - Español
    Paraguay - Español
    Perú - Español
    Philippines - English
    Polska - Polski
    Portugal - Português
    Puerto Rico - Español
    România - Română
    Schweiz - Deutsch
    Singapore - English
    Slovenija - Slovenščina
    Slovensko - Slovenčina
    South Africa - English
    Srbija - Srpski
    Suisse - Français
    Suomi - Suomi
    Sverige - Svenska
    Tunisie - Français
    Türkiye - Türkçe
    United Kingdom - English
    United States - English
    Uruguay - Español
    Venezuela - Español
    Việt Nam - Tiếng việt
    Ísland - Íslenska
    Österreich - Deutsch
    Česká Republika - Čeština
    Ελλάδα - Ελληνικά
    България - Български
    Казахстан - Русский
    Россия - Русский
    Україна - Українська
    ישראל - עברית
    الإمارات العربية المتحدة - العربية
    المملكة العربية السعودية - العربية
    مصر - العربية
    भारत - हिंदी
    ไทย - ไทย
    中国 - 简体中文
    台灣 - 繁體中文
    日本 - 日本語
    香港特別行政區 - 繁體中文
    대한민국 - 한국어
    English (Singapore)
    • Terms of use
    • Privacy & cookies
    • Trademarks
    • © Microsoft 2018