Solution to the cursor problem returned by Enterprise Library-data block Oracle

Source: Internet
Author: User
Tags oracle cursor

Using data block to operate Oracle yesterday, cursor is returned. A problem occurred during this period. It was very depressing and it was not solved after I found it all afternoon. You can't sleep in the morning. The solution is found. In fact, it is also strange that you have not read the document well. Record it here. So that other comrades can easily find a solution to my problem.

The problem is as follows:
I have such a process in Oracle

Procedure Listallstatic_users (Cur_static_userOut t_cursor)
Is
Begin
Open  Cur_static_user  For
Select   *   From Static_user;
End Listallstatic_users;

OnProgramIt is called as follows:

Database DB = Databasefactory. createdatabase ( " Oraserver " );
String Sqlcommand =   " Static_userpackage.listallstatic_users " ;
Dbcommandwrapper = DB. getstoredproccommandwrapper (sqlcommand );
Dataset dscustomers = DB. executedataset (dbcommandwrapper );
Datagrid1.datasource = Dscstomers;
Datagrid1.databind ();

The following problem occurs:

ORA-06550: 1st rows, 7th columns: PLS-00306: number of parameters or type error when calling 'listallstatic _ users' ORA-06550: 1st rows, 7th columns: PL/SQL: Statement ignored

Note:An error occurred while executing the current Web request. Check the stack trace information to learn about this error andCodeDetailed information about the cause of the error.

Exception details:System. data. oracleclient. oracleexception: ORA-06550: 1st rows, 7th columns: PLS-00306: number of parameters or type errors when calling 'listallstatic _ users' ORA-06550: 1st rows, 7th columns: PL/SQL: Statement ignored

Source error:

Row 44: Row 45: DataSet dscustomers = dB. executedataset (dbcommandwrapper );
Row 46: Maid = dscustomers; row 47: Maid ();


I thought my parameters were not correct, so I added the following sentence:

Dbcommandwrapper. addoutparameter ( " Cur_static_user " , Dbtype. object, 500 );

The results are the same. Later I tried it.

Oraclecommandwrapper. addparameter ( String , Dbtype, Int , Parameterdirection, Bool , Byte , Byte , String , Datarowversion, Object );

This method cannot be added.

Later, I went online for a long time and there was no progress. When I got up this morning, I still couldn't do anything. I occasionally opened the Enterprise Library release notes. rtf file in the Enterprise Library installation directory and found that there was such a paragraph

2.4 Data Access Application Block: Default Oracle cursor cur_out

The managed provider for Oracle requires you to explicitly bind your reference cursor in your parameter collection. this means you must explicitly create an output parameter for the cursor in your application code. however, that code will not be portable with database systems that do not require a parameter for the cursor. the Oracledatabase Allows you to create commands without specifying a cursor. It will create a cursor, named Cur_out , For commands that execute a stored procedure and do not include an output parameter for the cursor. this means that you can name your reference cursor as "cur_out" and the Data Access Application Block will bind it for you; you do not need to explicitly create an output parameter for the cursor. if your stored procedures use a cursor with a name other than "cur_out," you must explicitly add a parameter for each cursor to the command. similarly, if your Stored Procedure contains multiple cursors, you must explicitly add each cursor parameter to the command.
Now I understand. In my Oracle functions, my name Cur_static_user And default name Cur_out does not match.

So I changed the parameter name of my stored procedure,Cur_static_userChangeCur_out.

The problem is solved.

After testing, you can also use your own parameter name using the following method, instead of the default parameter name.
Alternatively
ProcedureReturns multiple cursor

My stored procedures:

Procedure Static_user_selectall
(Cur_out_f out t_out, cur_out_g out t_out)
  As  
  Begin  
  Open Cur_out_f For   Select   *   From Static_user;
  Open Cur_out_g For   Select   *   From Static_role;
  End ;

The Code is as follows:

Database DB = Databasefactory. createdatabase ( " Oraserver " );
String Sqlcommand =   " Static_userpackage.static_user_selectall " ;
Microsoft. Practices. enterpriselibrary. Data. Oracle. oraclecommandwrapper dbcommandwrapper = (Microsoft. Practices. enterpriselibrary. Data. Oracle. oraclecommandwrapper) dB. getstoredproccommandwrapper (sqlcommand );
Dbcommandwrapper. addparameter ( " Cur_out_f " , Oracletype. cursor, 0 , Parameterdirection. output, True , 0 , 0 , String. Empty, datarowversion. Default, convert. dbnull );
Dbcommandwrapper. addparameter ( " Cur_out_g " , Oracletype. cursor, 0 , Parameterdirection. output, True , 0 , 0 , String. Empty, datarowversion. Default, convert. dbnull );
Dataset dscustomers = DB. executedataset (dbcommandwrapper );
Datagrid1.datasource = Dscustomers. Tables [ 0 ];
Datagrid1.databind ();
Datagrid2.datasource = Dscustomers. Tables [ 1 ];
Datagrid2.databind ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.