c# – ORA-01008绑定了所有变量

我正在使用System.Data.OracleClient,它按名称进行参数绑定,并验证CommandText和Parameters是否同步:
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) + ".");
        }
    }

还有一个查询抛出ORA-01008:并非所有变量都绑定.当手动将参数值插入有问题的CommandText时,查询运行,因此CommandText和Parameters-values应该没问题.我正在使用:作为变量和参数名称的前缀,它适用于其他查询.

如何查明此异常的原因?

解决方法

错误是没有为null值指定dbnull.Value.所以
new OracleParameter(":Foo",item.Foo)

不得不预先放置

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

我认为它早期使用ODT.NET而没有空检查,但还没有确认.显然,System.Data.OracleClient正在删除带有null值的参数.

相关文章

C#项目进行IIS部署过程中报错及其一般解决方案_c#iis执行语句...
微信扫码登录PC端网站应用的案例(C#)_c# 微信扫码登录
原文地址:http://msdn.microsoft.com/en-us/magazine/cc163...
前言 随着近些年微服务的流行,有越来越多的开发者和团队所采...
最近因为比较忙,好久没有写博客了,这篇主要给大家分享一下...
在多核CPU在今天和不久的将来,计算机将拥有更多的内核,Mic...