i would like to know how to determine a transaction is already rollback so that we dont have to reroll back again and get an exception like below:
This SqlTransaction has completed;
it is no longer usable. at System.Data.SqlClient.SqlTransaction.Rollback()
Please help because when i tried to do this: objTrans.rollback() and i got the above exception.
Regards,If the SqlTransaction's Connection property is nothing, then the transaction is no longer valid (and you should not call Rollback() ). Here's the docs for a code sample:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqltransactionclasstopic.asp|||Thanks alot..
actually i have another issue that is somehow related to this thread, i m using dataAdater to populate my TreeView COntrol but if i refresh 2 browser at the same time it will give me 2 exception. The first exception is
1)There is already an open DataReader associated with this Connection which must be closed first.
2)The SqlCommand is currently busy Open, Fetching.
I m not so sure why can this be? i m doing recursive loop and below is my code
private void LoadNode()
{//clear the tree Component
TreeView1.Nodes.Clear();string Tsql;
TreeNode Node;Tsql="sp_framework_get_imis_function";
DataSet dsTree;dsTree=ExecuteDbConnection.fillDataset(Tsql,imis.framework.net.ImisUser .getDetails.userID);
int i=0;
TreeNode tempNode=null;
if (dsTree.Tables.Count <= 0) return;
while (i<= dsTree.Tables[0].Rows.Count -1)
{//create a new node for parent
//get the parent node
Node=new TreeNode();if (dsTree.Tables[0].Rows[i]["function_desc"].ToString()!=string.Empty|| dsTree.Tables[0].Rows[i]["function_desc_chinese"].ToString() !=string.Empty)
{
//desc_chinese is not null
if (dsTree.Tables[0].Rows[i]["function_desc"].ToString() !=string.Empty && dsTree.Tables[0].Rows[i]["function_desc_chinese"].ToString()!=string.Empty ) Node.Text=dsTree.Tables[0].Rows[i]["function_desc_chinese"].ToString()==null?dsTree.Tables[0].Rows[i]["function_desc"].ToString() :dsTree.Tables[0].Rows[i]["function_desc"].ToString() + "<br>"+dsTree.Tables[0].Rows[i]["function_desc_chinese"].ToString();
if(dsTree.Tables[0].Rows[i]["function_desc"].ToString()==string.Empty && dsTree.Tables[0].Rows[i]["function_desc_chinese"].ToString()!=string.Empty )Node.Text=dsTree.Tables[0].Rows[i]["function_desc_chinese"].ToString();
if(dsTree.Tables[0].Rows[i]["function_desc"].ToString()!=string.Empty && dsTree.Tables[0].Rows[i]["function_desc_chinese"].ToString()==string.Empty ) Node.Text=dsTree.Tables[0].Rows[i]["function_desc"].ToString();
}
else
{
//throw exception because both desc and desc_chinese is not null.
return;
}Node.SelectedImageUrl=dsTree.Tables[0].Rows[i]["img_selected"].ToString();
Node.ImageUrl =dsTree.Tables[0].Rows[i]["img"].ToString();
if (dsTree.Tables[0].Rows[i]["program"].ToString() !="")
{
Node.NavigateUrl ="index.aspx?pageID=" +dsTree.Tables[0].Rows[i]["function_id"];
Node.Target="WorkFrame";
}tempNode=Node;
TreeView1.Nodes.Add(Node);
ChildNode(tempNode,Convert.ToInt32(dsTree.Tables[0].Rows[i]["function_id"]));
i=i+1;}
}//end sub
private void ChildNode(TreeNode node,int functionID)
{
try
{
TreeNode nodeX;
string userID=imis.framework.net.ImisUser.getDetails.userID;
string tSql;
string TempSQL;if (imis.framework.net.ImisUser.getDetails.userID ==null)
return;
TempSQL="sp_framework_get_imis_function_child_id";
DataSet dsChild;
dsChild=ExecuteDbConnection.fillDataset(TempSQL,functionID,userID);int i=0;
if (dsChild.Tables[0].Rows.Count >0)
{
while (i <=dsChild.Tables[0].Rows.Count-1)
{
//get all the child of the belong the the first level nodes
nodeX=new TreeNode();if (dsChild.Tables[0].Rows[i]["function_desc"].ToString()!=string.Empty || dsChild.Tables[0].Rows[i]["function_desc_chinese"].ToString() !=string.Empty)
{
//desc_chinese is not null
if (dsChild.Tables[0].Rows[i]["function_desc"].ToString() !=string.Empty && dsChild.Tables[0].Rows[i]["function_desc_chinese"].ToString()!=string.Empty) nodeX.Text=dsChild.Tables[0].Rows[i]["function_desc_chinese"].ToString()==null?dsChild.Tables[0].Rows[i]["function_desc"].ToString() :dsChild.Tables[0].Rows[i]["function_desc"].ToString() + "<br>"+dsChild.Tables[0].Rows[i]["function_desc_chinese"].ToString();
if(dsChild.Tables[0].Rows[i]["function_desc"].ToString()==string.Empty && dsChild.Tables[0].Rows[i]["function_desc_chinese"].ToString()!=string.Empty)nodeX.Text=dsChild.Tables[0].Rows[i]["function_desc_chinese"].ToString();
if(dsChild.Tables[0].Rows[i]["function_desc"].ToString()!=string.Empty && dsChild.Tables[0].Rows[i]["function_desc_chinese"].ToString()==string.Empty) nodeX.Text=dsChild.Tables[0].Rows[i]["function_desc"].ToString();
}
else
{
//throw exception because both desc and desc_chinese is not null.
}//nodeX.Text= dsChild.Tables[0].Rows[i]["function_desc"].ToString();
nodeX.SelectedImageUrl=dsChild.Tables[0].Rows[i]["img_selected"].ToString();;
nodeX.ImageUrl =dsChild.Tables[0].Rows[i]["img"].ToString();if (dsChild.Tables[0].Rows[i]["program"].ToString() != "")
{
nodeX.NavigateUrl="index.aspx?pageID=" +dsChild.Tables[0].Rows[i]["function_id"];
nodeX.Target="WorkFrame";
}node.Nodes.Add(nodeX);
tSql="sp_framework_get_imis_function_child_id";
DataSet ds2=ExecuteDbConnection.fillDataset(tSql,Convert.ToInt32(dsChild.Tables[0].Rows[i]["function_id"]),userID);if (Convert.ToBoolean(ds2.Tables[0].Rows.Count > 0))
{
int j=0;
while (j <=ds2.Tables[0].Rows.Count -1)
{
//recursive way of getting all the child in the first level
TreeNode nodeY=new TreeNode();if (ds2.Tables[0].Rows[j]["function_desc"].ToString()!=string.Empty || ds2.Tables[0].Rows[j]["function_desc_chinese"].ToString() !=string.Empty)
{
//desc_chinese is not null
if (ds2.Tables[0].Rows[j]["function_desc"].ToString() !=string.Empty && ds2.Tables[0].Rows[j]["function_desc_chinese"].ToString()!=string.Empty) nodeY.Text=ds2.Tables[0].Rows[j]["function_desc_chinese"].ToString()==null?ds2.Tables[0].Rows[j]["function_desc"].ToString() :ds2.Tables[0].Rows[j]["function_desc"].ToString() + "<br>"+ds2.Tables[0].Rows[j]["function_desc_chinese"].ToString();
if(ds2.Tables[0].Rows[j]["function_desc"].ToString()==string.Empty && ds2.Tables[0].Rows[j]["function_desc_chinese"].ToString()!=string.Empty)nodeY.Text=ds2.Tables[0].Rows[j]["function_desc_chinese"].ToString();
if(ds2.Tables[0].Rows[j]["function_desc"].ToString()!=string.Empty && ds2.Tables[0].Rows[j]["function_desc_chinese"].ToString()==string.Empty) nodeY.Text=ds2.Tables[0].Rows[j]["function_desc"].ToString();
}
else
{
//throw exception because both desc and desc_chinese is not null.
}//nodeY.Text=ds2.Tables[0].Rows[j]["function_desc_chinese"].ToString()==null?ds2.Tables[0].Rows[j]["function_desc"].ToString() :ds2.Tables[0].Rows[j]["function_desc"].ToString() + "<br>"+dsChild.Tables[0].Rows[j]["function_desc_chinese"].ToString() ;
nodeY.SelectedImageUrl=ds2.Tables[0].Rows[j]["img_selected"].ToString();
nodeY.ImageUrl =ds2.Tables[0].Rows[j]["img"].ToString();if (ds2.Tables[0].Rows[j]["program"].ToString() != "")
{nodeY.NavigateUrl="index.aspx?pageID=" +ds2.Tables[0].Rows[j]["function_id"];
nodeY.Target="WorkFrame";
}
nodeX.Nodes.Add(nodeY);
ChildNode(nodeY,Convert.ToInt32(ds2.Tables[0].Rows[j]["function_id"]));
++j;
}//end while
}//end if
++i;
}//end while
}//end if
}
catch(Exception err)
{
imis.framework.net.ApplicationLog.writeError(err,"TreeView");}
}//end sub
Please advise, i m using dataAdater purely.|||I'm not sure. I'd advise you to repost the previous message in a new thread so that more people will take a look at it.sql
No comments:
Post a Comment