Solved

ORA-01000: maximum open cursors exceeded C#

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

 

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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.

828 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