Sunday 15 May 2011

c# - sp_setapprole error when threading: "Impersonate Session Security Context" cannot be called in this batch because a simultaneous batch has called it -



c# - sp_setapprole error when threading: "Impersonate Session Security Context" cannot be called in this batch because a simultaneous batch has called it -

when calling sp_setapprole on sql server 2014 threaded app error:"impersonate session security context" cannot called in batch because simultaneous batch has called it. connections not pooled far know , new connection created on each phone call i'm not sure collision happening. here test app creates error:

using microsoft.applicationblocks.data; using system; using system.collections.generic; using system.data; using system.data.sqlclient; using system.threading.tasks; namespace pleasebreak { class programme { static string connectionstring = "data source=<sql db server>; initial catalog=<sql db name>; user id=<user name>; pwd=<password>; enlist=false; persist security info=true; pooling=false; multipleactiveresultsets=true; app=<appname>;"; static int threadcount = 3; static int loopcount = 100000; static void main(string[] args) { var tasks = new list<task>(); (var = 0; < threadcount; i++) { tasks.add(task.factory.startnew(work)); } task.waitall(tasks.toarray()); } static void work() { (var = 0; < loopcount; i++) { using (var connection = new sqlconnection(connectionstring)) { connection.open(); seek { sqlhelper.executenonquery(connection, commandtype.storedprocedure, "sp_setapprole", new sqlparameter[] { new sqlparameter { parametername = "@return_value", direction = parameterdirection.returnvalue, dbtype = dbtype.int32 }, new sqlparameter { parametername = "@rolename", direction = parameterdirection.input, dbtype = dbtype.ansistring, value = <approle name> }, new sqlparameter { parametername = "@password", direction = parameterdirection.input, dbtype = dbtype.ansistring, value = <app role password> }, }); } grab (exception ex) { } } } } } }

it appears multipleactiveresultsets issue. 1 time added multipleactiveresultsets=false connection problem went away.

c# .net sql-server

No comments:

Post a Comment