Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

徵狀

假設您有一個 Transact-sql 的儲存程式,如下所示,此程式會採用一個包含 限制 作為引數的資料表值參數(TVP):

create type TestTvpType as table   

(

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

  data int

); 

go 

create procedure TestTvpProc @tvp TestTvpType readonly

as

begin

  select * from @tvp;

end;

go

在從 SQLCLR 存儲程式呼叫此程式的情況下,如果該引數違反該 限制 ,您可能會在收到「限制侵犯」錯誤訊息時,錯誤地接收系統 assert。

下列是針對預存程式產生限制違反之 SQLCLR 程式的範例:

[SqlProcedure]

public static void ClrProcCallingTsqlProcWithTvpArgument(out int sum)

{

       using (SqlConnection connection = new SqlConnection("context connection=true"))

       {

              sum = 0;

              DataTable myDataTable = 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);

              SqlParameter parameter = new SqlParameter();

              parameter.ParameterName = "@tvp";

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

              parameter.Value = myDataTable;

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

              command.CommandType = CommandType.StoredProcedure;

              command.Parameters.Add(parameter);

              connection.Open();

              using (SqlDataReader reader = command.ExecuteReader())

              {

                     while (reader.Read())

                     {

                           …;

                     }

              }

       }

}

解決方案

此問題已在 SQL Server 的下列累積更新中修正:

SQL Server 2016 RTM 的累積更新5

SQL Server 2016 SP1 的累積更新2

SQL Server 2014 的累積更新 4 Service Pack 2

注意 此更新會導致傳回正確的「限制違反」錯誤訊息。

每個新的 SQL Server 累積更新包含前一個累積更新中所包含的所有修復程式和安全性修正程式。 查看 SQL Server 的最新累計更新:

SQL Server 2016 的最新累計更新

SQL Server 2014 的最新累計更新

狀態

Microsoft 已確認本篇文章<適用於>一節所列之 Microsoft 產品確實有上述問題。

 

參考

瞭解 Microsoft 用於描述軟體更新的 術語

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×