Solved

ORA-01000: maximum open cursors exceeded C#

Posted on 2009-03-31
13
1,773 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
 

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 20

Accepted Solution

by:
informaniac earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now