Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ORA-01000: maximum open cursors exceeded C#

Posted on 2009-03-31
13
Medium Priority
?
1,884 Views
Last Modified: 2012-05-06
I'm trying to access to another database table during an function but this exception kept appearing @ the 2nd "drOracle = cmdOracle.ExecuteReader();"

I hope someone can have me clear this error, thanks.
try
                {
                    localSQL = "SELECT KEYID,PKEYID, PRODUCT_NAME,PRODUCT_DESC FROM PRODUCT_NODE START WITH PKEYID IS NULL CONNECT BY PRIOR KEYID = PKEYID ORDER BY DT_NODE_NAME";
                    OracleCommand cmdOracle = new OracleCommand(localSQL, localConnection);
                    cmdOracle.CommandType = CommandType.Text;
                    OracleDataReader drOracle = cmdOracle.ExecuteReader();
 
                    DataTable ordt = new DataTable();
                    OracleDataAdapter orda = new OracleDataAdapter();
                    orda.SelectCommand = cmdOracle;
                    orda.Fill(ordt);
                    drOracle.Close();
                    
                    TreeNode nodeCheck = null;
                    TreeNode[] node = null;
                    string strText = string.Empty;
                    string[] strList = null;
                    string strDesc = null;
                    
                    foreach (DataRow dr in ordt.Rows)
                    {
                        nodeCheck = new TreeNode();
                        nodeCheck.Name = dr[0].ToString();                        
                        strText = dr[2].ToString();
                        strDesc = dr[3].ToString();
                        strList = strText.Split('.');
 
                        nodeCheck.Text = strList[strList.Length - 1];
 
                        if (dr[1] != DBNull.Value)
                        {
 
                            node = treeScadaItems.Nodes.Find(dr[1].ToString(), true);
                                if (strList.Length == 5)
                                {
                                    nodeCheck.Text = nodeCheck.Text + ": " + strDesc;
                                    node[0].Nodes.Add(nodeCheck);
 
                                    localSQL = "SELECT * FROM OPC_DT_PT WHERE PKEYID LIKE '" + dr[0].ToString() + "'";
                                    cmdOracle = new OracleCommand(localSQL, localConnection);
                                    cmdOracle.CommandType = CommandType.Text;
                                    //Exception Error appearing here.
                                    drOracle = cmdOracle.ExecuteReader();
 
                                    while (drOracle.Read())
                                    {
                                    }
                                }
                                else
                                { node[0].Nodes.Add(nodeCheck); }
                        }                        
                        else
                        {
                            treeScadaItems.Nodes.Add(nodeCheck);
                        } 
                        nodeCheck.Tag = dr[0].ToString();
                    } 
                }

Open in new window

0
Comment
Question by:csharp_learner
  • 7
  • 6
13 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 24026923
while (drOracle.Read())
                                    {
                                    }
drOracle.Close();

Try this code

0
 

Author Comment

by:csharp_learner
ID: 24027017
After trying the code you mentioned the program compile for qite some time and pop-up:
ContextSwitchDeadlock was detected @ the line "drOracle = cmdOracle.ExecuteReader();"
0
 
LVL 20

Expert Comment

by:informaniac
ID: 24027101
Does this help?

OracleDataReader drOracle1 = cmdOracle.ExecuteReader();

while (drOracle1.Read())
                                    {
                                    }
drOracle1.Close();
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:csharp_learner
ID: 24027136
The same error "ContextSwitchDeadlock was detected" @ the line
"OracleDataReader drOracle1 = cmdOracle.ExecuteReader();"
0
 
LVL 20

Expert Comment

by:informaniac
ID: 24027159
Just try by writing this in line no 13

cmdOracle = null;

or try by creating a new oracle command
0
 

Author Comment

by:csharp_learner
ID: 24027198
In both cases the same error came out.
0
 
LVL 20

Accepted Solution

by:
informaniac earned 2000 total points
ID: 24027274
Well that's the first time i've seen/heard that error, googling gave me this

http://harriyott.com/2006/05/contextswitchdeadlock-was-detected.aspx
0
 

Author Comment

by:csharp_learner
ID: 24027329
I did as the site instructed and unchecked the "ContextSwitchDeadlock " the error did not appear.
But i don't think it's the solution I'm looking for, as the compliation time took very long.
0
 
LVL 20

Expert Comment

by:informaniac
ID: 24027968
Have u closed the connection?
0
 

Author Comment

by:csharp_learner
ID: 24035366
If you mean closing the 2nd drOracle1 ,yes I've closed it.
0
 

Author Comment

by:csharp_learner
ID: 24037313
I have narrowed down to this code...
But when i put the drOracle.Close(); before the while loop i will get an
Exception Error:"Operation is not valid due to the current state of the object"
If i put the drOracle.Close();  after the while loop it'll prompt the ContextSwitchDeadlock error.
				    drOracle = null;
                                    localSQL = "SELECT * FROM PRODUCT_PT WHERE PKEYID LIKE '" + dr[0].ToString() + "'";
                                    OracleCommand cmdOracle1 = new OracleCommand(localSQL, localConnection);
                                    cmdOracle1.CommandType = CommandType.Text;
                                    drOracle = cmdOracle1.ExecuteReader();
                                    //drOracle.Close();
                                    while (drOracle.Read())
                                    {
                                    }
                                    //drOracle.Close();

Open in new window

0
 

Author Closing Comment

by:csharp_learner
ID: 31564727
I've decided to go with unchecking Context error for now.
0
 
LVL 20

Expert Comment

by:informaniac
ID: 24056733
Well I was just searching the net and I came across this article.

Possibly this might help u.

http://forums.devx.com/showthread.php?t=16742

http://www.dotnet247.com/247reference/msgs/38/190956.aspx
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question