.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

MySql Transaction inside a loop.

Posted By:      Posted Date: October 01, 2010    Points: 0   Category :ASP.Net

Hi.  I'm trying to delete a bunch of records in mysql.  The record info to delete (userid, name) is stored in an arraylist.  It seems to only delete the first record and gives an error ("Transaction has already been rolled back or is not pending.") afterwards.  I have the transaction commit inside the loop which I think is the issue but not sure how to go further if I bring it outside of the loop.  Here's the relevant bits of the code.  Thanks in advance.

                ArrayList alist = new ArrayList();

                //alist gets populated with data like (12345,robot)(23456,car) here.

                    MySqlConnection conn2 = new MySqlConnection(query_connection);

View Complete Post

More Related Resource Links

SSIS For Each loop with data flow hangs on DTC (SID -2) when inside transaction

The short story: I have a data flow inside a For Each container that is inside a sequence container.  A transaction is established at the sequence container, with Isolation Level Serializable.  The For Each container is limited to execute only 4 iterations.  The data flow iterates once fine, but the second iteration hangs.  The Activity Monitor shows the process is waiting on a another process with a SID of -2.  From other research in the past, I have found that this is an internal process dedicated to DTC (Distributed Transaction Coordinator). Environment: Microsoft SQL Server 2005 (SP3) on Windows 2008 R2 Standard.  I'm using SQL Server BIDS 2005 for building these packages.  I also have SQL Server 2008 installed and the databases are installed there. The details: The data flow merges data from the same table in two databases, source and target, using a Merge Join component.  It then performs a few transformations and lookups from other tables in the target DB to get IDs.  Then it inserts new records into the target DB or updates existing records in the target DB.  The two source tables are using OLE DB Source components with customized queries.  The insert target component is an OLE DB Destination and the update target component is an OLE DB Command.  In this particular scenario,

Calling Javascript from loop inside a Sub

Hi Guys, I had a copyfile sub that worked fine on my local testing environment in VWD 2008, but now that it is on the server does not work. I assume it is because it is looking on the server for the files, not the local client machine. I am now trying to use client side Javascript to mimic the process. I have created a JS function to do it, but I can't get it to call the JS function inside my VB Sub. Here's the code, thanks to all replyers in advance! Public Function Copy_Photo(ByVal path_in As String, ByVal newname As String) As String Try Dim ret_path As String = Me.Master.get_mug_shot_folder ret_path += newname Response.write("<script type = 'text/javascript'>CopyPhoto('" & path_in & "','" & ret_path & "');</script>") Return ret_path Catch ex As Exception msg_div.InnerText = "ERROR: Could not properly copy file " & path_in & " to location " End Try End Function    Notice how I tried using the Response.write method. It gives me an Object Required error everytime. Here's the JS function: function CopyPhoto(oldFile, newfile) { alert(oldfile + " " + newfile); var fso; fso = new ActiveXObject("Scr

Create task activity break out inside a While loop

Hi I have developed a sharepoint state machine workflow. I want to assign a same task to more than one users, but unfortunatly, I cannot give the attribute "AssignTo" to more users in the code, even like this:"this.workflowTask1Properties.AssignedTo = "mydomain\\user01;mydoman\\user02", that will result in an empty value to the attribure.So, I involved the createtask activity in a While loop so I can asign deferent user in each loop, but It's very stange,  the loop always stopped in the second time, does anybody have met this issue?I have referensed Amit's question:http://social.msdn.microsoft.com/forums/en-US/windowsworkflowfoundation/thread/b238978d-f330-420c-823e-b77b0e19414d?prof=requiredbut I have no define the "correlation refernce " in my workflow.my code is here:public SPWorkflowTaskProperties workflowTask1Properties;public int abc;...private void OnWorkflowActivated(object sender, ExternalDataEventArgs e)        {            ...           this.abc = 0;           ...        }...private void CreateTask1(object sender, EventArgs e)        { 

How to create a second independent transaction inside a CLR stored procedure?

I use the context connection for the "normal" work in the CLR procedure.But I need to commit some data in every case. So I need to create a second transaction which is independent from the calling transaction.What is the best way to do this inside a CLR procedure?Thanx a lot

SQL-transaction for foreach/for loop


i am making a web application in which at one time i have to insert the vales into three table..

first table will generate scope_identity,

then in foreach loop values are inserted in 2nd table with ref of scope identity

and then same with the 3rd table

problem is i dont know how to put transaction in foreach loop......

please help me.......

here is my dummy code please help me....

SqlConnection con = new SqlConnection("server=xxxx;uid=xxxx;password=xxx;database=xxxx;connect timeout=3600");
        SqlCommand cmd = new SqlCommand("insert into test(a,b,c,d,e,f,g,h) values ('a','b','c','d','e','f','g','h');select scope_identity()", con);
        decimal idd = (decimal)cmd.ExecuteScalar();

        for (int i = 0; i < 15; i++)
            SqlCommand cmd1 = new SqlCommand("insert into test1(a,b,c,d,e,f,g,h) values ('"+idd.ToString()+"','b','c','d','e','f','g','h')", con);
        for (int i = 0; i < 15; i++)
            SqlCommand cmd2 = new SqlCommand("insert into test2(a,b,c,d,e,f,g,h) values ('&

WCF Async method inside a WCF transaction


Can WCF async methods be called  from within a WCF transaction?

Normally, one would only call synchronous methods from within a WCF transaction.

ajax.beginform inside a for loop


so I am using a foreach loop to iterate through comments. The comment section is wrapped inside "Comments" div. My function **DeleteComment** fetches comments again once you delete a comment and rebinds it to the control. However, after you delete a comment, anytime you try to delete another comment, the commentId of the very first deleted comment would keep getting passed to **DeleteComment** function instead of the passing the commentId of the comment you are trying to delete. If you refresh the page, then you can delete ONE comment again, and the same problem if you try to delete another. 
     <% foreach (var item in Model) { %>

Error trying to set Correlation Token at runtime for ReAssigning Task inside while loop.


Hello Friends,

I have developed a custom sequential WF in VS 2010 using custom WorkFlow Content Type and ASPX forms.

Requirements are as below:

1.WF creates an approval task for User A. If User A rejects,then WF completes.
2.If User A approves,task is assigned to User B. If User B approves,then WF completes.
3.Is User A approves and User B rejects,then I need to ReAssign the task to User A.

I am facing problems in the 3rd point above.
I have a while loop having a Sequence Activity and the activities: CreateTaskWithContentType,onTaskChanged and CompleteTask are inside the Sequence Activity.

I am aware that the Correlation Token has to be set at design time in the VS 2010 WF Designer.

The issue is of dynamically assigning Correlation Tokens(Task Tokens) to the activities: CreateTaskWithContentType,onTaskChanged and CompleteTask which are inside Sequence Activity(Inside While Loop).

My Code:
CorrelationToken C_Token =
                 new System.Workflow.Runtime.CorrelationToken();
createTaskWithContentType1.CorrelationToken = C_Token;

I get the error:"This operation can not be performed at runtime" when trying to assign Correlation Token dynamically as above.

Can anyone please hel

Passing Parameters to Execute SQL task which is inside a For Loop Container



I have a requirement.

In this I will get a value of 50 ids from one table.

I have an sp which will take ids as input parameter and insert values into another table.

My Problem is I am having a for loop container with me and inside that i have execute sql task in which I have stored procedure.

How can i map the id parameter to the execute sql task variable whichi is inside a forloop.




Thanks, A2H

Object Value lost in script component inside for loop container

Hi All,

I need your expert advice here,

I have 5000 records to transform into csv file and due to the application limitation, the upload module to upload those 5000 records only can be done by batch of 100-200 record at one time.

Because of this, i try to use for loop to split the records into a few files e.g EE_1.csv, EE_2.csv.

The records was retrieved and saved into an object variable (ResultSet) before entering the For Loop flow

The issue i encounter, when it was on the 1st loop everything was fine, it is manage to generate X Records i specified but when it go for 2nd loop, the ResultSet is returning 0 Records..when the actual total records is 5000

Anyone can help this newbie what are the mistakes i made ?

The logic is something like

Public Overrides Sub CreateNewOutputRows()
oledbAdapter = New OleDb.OleDbDataAdapter
dataTable = New DataTable

oledbAdapter.Fill(dataTable, Me.Variables.resultset)
StartPoint = Me.Variables.FilesNumber 'To know which row to start
StartPoint = (StartPoint - 1) * Me.Variables.MaxRecord
EndPoint = (StartPoint + Me.Variables.MaxRecord) - 1

If dataTable.Rows.Count - 1 < EndPoint Then
EndPoint = dataTable.R

TSQL help please - dynamic sql inside WHILE loop


I would like to store data into different temp tables based on different WHERE clause. I used the below script but it throws error. Please help

My Script:



@counter int



@counter = 0



@counter <

Using a Create Task Activity inside a While loop



I have developed a sharepoint sequential workflow. It consists of a while loop, inside which there are 2 activities (in a sequence)-

1. Create task activity

2. Code activity

Code activity is used to set the test condition of the while loop.

The loop executes successfully on the first iteration. But on the subsequent iterations, an error occurs in the workflow.

My requirement is to create the task repeatedly as long as while loop doesnt exit. Is this possible? Any suggestions would be valuable.



Rendering controls via Loop inside Render


I am creatin a server control where
some controls are being rendered inside  `protected override void Render(HtmlTextWriter writer)`

    writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
    writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + "butto_Foo1");
    writer.AddAttribute(HtmlTextWriterAttribute.Value, "Button1");
    writer.RenderEndTag(); //button
    writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
    writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + "butto_Foo2");
    writer.AddAttribute(HtmlTextWriterAttribute.Value, "Button2");
    writer.RenderEndTag(); //button       

This way buttons are rendered on design view as well. 
The problem is that number of buttons to render is dynamic based on data in xml file (even if the data was static, the number of button is about 12 and I don't think it is wise to copy paste the same code above 6 times...).

I thought by using loop

SQL dynamic query inside BEGIN Transaction


Hi All,

I am working on stored procedure and all update statements are inside "BEGIN TRAN" and COMMIT..now i expect if all statement runns succesfully then to return 1 else from catch block it should return error message..

i wrote stored procedure mentioned below ...

when i execute this stored procedure i see three output ..including return value..


-- =============================================
-- Author:		<>
-- Create date: <19 March 2010>
-- Description:	<Update FPA_CLAIM_MAN ,FPA_CLAIM_DETAIL ,
-- =============================================
ALTER PROCEDURE [dbo].[SP_UpdateFpaByFiAdmin](
	-- Add the parameters for the stored procedure here
	@COMMENT VARCHAR(1000) = ' ',
	@TOTA_CLAIM_AMT bigint,

	@bu_ecode VARCHAR(20),

	@total_bal bigint ,

	@STRING_Employee_Limit_distribution  VARCHAR(MAX) = '',
	@STRING_Employee_FPA_distribution  VARCHAR(MAX) = ''


Microsoft's Collaborative Application Markup Language (CAML) Loop

discovered an interesting error recently while working with Microsoft's Collaborative Application Markup Language (CAML) that, surprisingly, had received no ink. Partly what surprises me about this is that the error may require you to rewrite large sections of your code if you haven't previously considered this SharePoint limitation. I'll start with some context, but first of all the error is:

Accessing the different controls inside a GridView control

how we can access a particular control which resides inside a GridView control. In this article I will show you how you can access different controls inside a GridView control. We will see how we can access a TextBox control, a DropDownList control and a ListBox control. If you are working with ASP.NET 1.X then you might want to check out my article Accessing Different Controls Inside a DataGrid.

How To Add calendar control inside a GridView

This article show hot to add calendar control inside a GridView with code in c#
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend