c# - sp_setapprole error when threading: "Impersonate Session Security Context" cannot be called in this batch because a simultaneous batch has called it -
calling sp_setapprole to SQL Server 2014 from a thread app we get the error: "Can not say holds session security context" as the This can be batch because the batch has called it together. As far as I know and a new connection is made on each call, connections are not deposited so I am not sure where the collision is occurring. Here's the test app that makes an error:
uses Microsoft. ApplicationBlocks.data; Using the system; Using System.Collections.Generic; Using System.Data; Using System.Data.SqlClient; System usage threading. Task; Namespace PleaseBreak {class Program {static string ConnectionString = "Data Source = & LT; SQL Server DB & gt ;; initial catalog = & LT; SQL DB name & gt ;; User ID = & LT; username & gt ;; pwd = & LT; password & gt should ;; = false; security Continue info = true; pooling = false; Akadikaktivarsltssets = true, APP = & lt; APPNAME & gt ;; "; Static Int ThreadCount = 3; Fixed int loopcount = 100000; Fixed zero main (string [] args) {var task = new list & amp; Tasks & gt; (); {Tasks.Add (Task.Factory.StartNew (work)) for (; I & lt; THREADCOUNT; i = 0 i ++); } Work. Waiting for all (work. } Static (VAR to void function () {i = 0; i & LT; LoopCount; i ++) using {(var connection = new SqlConnection (ConnectionString)) {ConnectionkOpen (); {SqlHelper.ExecuteNonQuery (Connection, CommandType.StandardProcessor, "SpeedSetProp", New SQLPMMER [] {New SQLPMMRER {parameterName = "@RigR_URR", Direction = Parameter Direction. Return Value, DBTP = DBTIP.INP32}, New SQLParameter {parameterName = @rolename ", direction = ParameterDirection.Input, DbType = DbType.AnsiString, value = & LT; APPROLE name & gt;}, new SqlParameter {ParameterName =" @password ", direction = ParameterDirection.Input, DbType = DbType.AnsiString, Value = & lt; app row The text after the "itemprop =" l = password & gt;},});} hold (exception pre) {}}}}}}
it seems that MultipleActiveResultSets issue was that once we Malteeplaktiv Rijltsset add the connection to false problem went far away.
Comments
Post a Comment