ORA-01008 with all variables bound ORA-01008 with all variables bound oracle oracle

ORA-01008 with all variables bound


The mistake was not specifing DBNull.Value for null-values. So

new OracleParameter(":Foo", item.Foo)

had to preplaced with

item.Foo == null     ? new OracleParameter(":Foo", DBNull.Value)     : new OracleParameter(":Foo", item.Foo)

I think it was working earlier with ODT.NET without null-checks, but have not confirmed it. Apparently System.Data.OracleClient is dropping parameters with null-value.


If you pass null as parameter value, you get "Not all variables bound" If you pass DBNull.Value you get runtime error somewhere in the OracleClient. To pass NULL, use string.Empty, OracleClient converts it to NULL for any database type.


If you have more than one parameter, you need to set BindByName to true. For example:

OracleCommand cmd = con.CreateCommand();cmd.BindByName = true;cmd.Parameters.Add(new OracleParameter("parameter1", parameter1));cmd.Parameters.Add(new OracleParameter("parameter2", parameter2));