4

I'm trying to feed sqlcommand with more parameters than it uses. Because of that I'm getting exception ORA 01036. The description leads me to a fact that I can only pass parameters that will actually be used in the query.

I cannot find it anywhere - is it really true? It seems pretty stupid and limited to me...

4
  • Why would you want to pass more parameters? Commented Nov 5, 2012 at 15:41
  • @w0lf, from top of my head - because I have a generic parameters base class? Or there's a lot of parameters that I don't want to prepare by hand everytime. It WORKS for Postgres and SqlServer... Commented Nov 5, 2012 at 15:44
  • 1
    @IAmDeveloper Wow, I never realized that until now. Just checked in SQL Server and it does work. Commented Nov 5, 2012 at 15:49
  • can u give a simple example of what you're trying to do? Commented Nov 5, 2012 at 16:27

1 Answer 1

1
  1. I attempted to recreate your situation using System.Data.SqlClient.SqlConnection to connect to an Oracle database and was unsuccessful.

  2. Using System.Data.OracleClient.OracleConnection I was able to test a query with and without parameters. The below code is successful with the uncommented 'string sql ...'. The commented 'string sql' will encounter the same error mentioned in your question.

        StringBuilder sb = new StringBuilder ();
    
        string sql = "SELECT CASE_ID, CLAIM_NR, CLAIM_PHS_CD FROM TABLENAME WHERE CASE_ID = :ci";
        //string sql = "SELECT CASE_ID, CLAIM_NR, CLAIM_PHS_CD FROM TABLENAME";
    
        using ( OracleConnection connection = new OracleConnection ( RegistryConnectionInformation.GetDBConnString () ) )
        {
            OracleParameter ci = new OracleParameter();
            ci.ParameterName = "ci";
            ci.Value = "12345";
    
            OracleCommand command = new OracleCommand ( sql, connection );
            command.Parameters.Add ( ci );
    
            connection.Open ();
            OracleDataReader reader = command.ExecuteReader ();
    
            try
            {
                while ( reader.Read () )
                {
                    sb.Append ( string.Format ( "{0} - {1} - {2}\n", reader [ 0 ], reader [ 1 ], reader [ 2 ] ) );
                }
            }
            catch ( Exception ex )
            {
                sb.Append ( string.Format ( "{0}\n\n{1}", ex.Message, ex.StackTrace ) );
            }
            finally
            {
                reader.Close ();
            }
        }
    
        return sb.ToString ();
    
  3. This leads me to believe you are correct: when querying Oracle, the number of paramaters passed in the command must match the number of paramaters in the query.

    a. When working with Oracle, I would also recommend you keep your paramaters in the same order as their usage in the query. Depending on what DLL you are using, the paramaters do not map based on paramater name, but by order of insertion.

Dave

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.