sql - Stored procedure causing transaction error while executing from C# application -


i have following stored procedure written in sql database. executes 2 procedures in different databases. inner procedures simple update , insert queries without explicit transaction statement applied.

alter procedure [dbo].[usp_1] @userid nvarchar(max), @report nvarchar(max), @sqlerrormsg nvarchar(max) output  begin exec    @ret = [db1].[dbo].[usp_2]                     @user = @userid,                     @msg = @sqlerrormsg output,                     @date = @reportdate              set @sqlerrormsg = 'report update status: ' + @sqlerrormsg              exec    @ret = [db2].[dbo].[usp_3]                     @userid = @userid,                     @msg = @sqlerrormsg output,                     @date = @reportdate      end 

this procedure runs when execute in sql management studio. when run using c# code calls procedure, following error:

the current transaction cannot committed , cannot support operations write log file. roll transaction. current transaction cannot committed , cannot support operations write log file. roll transaction.

c# code: (conn defined outside proper connection string , tested)

public int upload_excel_timer(string userid, string report, out string message) {     int ret;      sqlcommand cmd = new sqlcommand("usp_1", conn);     cmd.commandtype = commandtype.storedprocedure;     cmd.parameters.addwithvalue("@userid", userid);     cmd.parameters.addwithvalue("@report", report);      sqlparameter outputparameter = cmd.parameters.add("@sqlerrormsg", sqldbtype.nvarchar, 255);     outputparameter.direction = parameterdirection.output;       sqlparameter returnparameter = cmd.parameters.add("retval", sqldbtype.int);     returnparameter.direction = parameterdirection.returnvalue;      try     {         if (conn.state.equals(connectionstate.closed))             conn.open();         int tempval = cmd.executenonquery();         ret = convert.toint32(returnparameter.value);         message = outputparameter.value.tostring();     }     catch (exception e)     {         ret = -1;         message = e.message;     }         {         conn.close();     }     return ret; } 


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -