首页 > 代码库 > .NET访问Oracle数据库时报错

.NET访问Oracle数据库时报错

1.查询时条件中存在汉字导致oracle查询集为空

SQL:

StringBuilder sb = new StringBuilder(@"select *  from cux_ad_user a where 1=1 ");
            if (!string.IsNullOrEmpty(AD))
            {
                sb.AppendFormat("and lower(a.attribute15) like ‘%{0}%‘", AD);
            }

访问Oracle API:

OracleConnection mycon = new OracleConnection(connString);
            DataTable dt = new DataTable();
            OracleDataAdapter da = null;
            try
            {
                mycon.Open();
                da = new OracleDataAdapter(SQLString, mycon);
                da.Fill(dt);
                Log(SQLString);
                Log("###########################");
            }

处理方法:服务器中注册表的HKEY_LOCAL_MACHINE--->SYSTEM----->CurrentControlSet----->Control--->Session Manager---->Environment下新建字符串值nls_lang,值为

SIMPLIFIED CHINESE_CHINA.AL32UTF8

改完后一定重启,不重启发现不起作用。

.NET访问Oracle数据库时报错