I am running some code in .net, using the oracleclient in ,net. The SQL code can output a number of responses using the DBMS_PUT_LINE function, which I then retrieve with a call to DBMS_GET_LINE. If the output is just a specific line of text, ie 'DBMS_OUTPUT.PUT_LINE('USER IS NOT AVAILABLE : PLEASE CONTACT SYSTEM ADMINISTRATOR');' Then the call to get_line works fine, and I get that text. However, if the call is to output the SQL error message, 'DBMS_OUTPUT.PUT_LINE(SQLERRM);' then I get the following error returned, 'ORA-06502: PL/SQL: numeric or value error: hex to raw conversion error'
The really wierd thing, is if I then run exactly the same code a 2nd time (including a close and reconnect to the DB) then the call to get_line returns the actual error message being output.
My code essentially does the following:
Opens the DB connection Runs the SQL query with executeNonQuery Creates the output parameters like:
Dim anonymous_block = "begin dbms_output.get_line(:1, :2); end;"
aCmd.CommandText = anonymous_block
aCmd.Parameters.Add("1", OracleType.VarChar, 32000)
aCmd.Parameters("1").Direction = ParameterDirection.Output
aCmd.Parameters.Add("2", OracleType.Int32)
aCmd.Parameters("2").Direction = ParameterDirection.Output
Then runs another executeNonQuery to get the output.
then closes the db with .close()
But on the 2nd run, it gets the correct output. I there perhaps something I am not setting up correctly the 1st time?
Any thoughts? I can always just run the code twice, but that seems horribly inefficient.