I use System.Data.OracleClient , which binds parameters by name and checks if CommandText and Parameters are synchronized:
public string CommandText { get; set; } public IEnumerable<OracleParameter> Parameters { get; set; } private void VerifyThatAllParametersAreBound() { var variableNames = Regex.Matches(CommandText, ":\\w+") .Cast<Match>().Select(m => m.Value).ToArray(); var parameteterNames = Parameters.Select(p => p.ParameterName).ToArray(); var unboundVariables = variableNames.Except(parameteterNames).ToArray(); if (unboundVariables.Length > 0) { throw new Exception("Variable in CommandText missing parameter: " + string.Join(", ", unboundVariables) + "."); } var unboundParameters = parameteterNames.Except(variableNames).ToArray(); if (unboundParameters.Length > 0) { throw new Exception("Parameter that is not used in CommandText: " + string.Join(", ", unboundParameters) + "."); } }
Another request calls ORA-01008: not all variables bound . When parameter values ββare manually inserted into a commandText-violating query, the query is executed, so the CommandText and Parameters values ββshould be in order. I use: as a prefix for both variables and parameternames, and it works for other queries.
How can I determine the cause of this exception?
source share