首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OledbException row-00001无法分配内存

OledbException row-00001无法分配内存
EN

Stack Overflow用户
提问于 2015-09-01 20:36:32
回答 1查看 2.3K关注 0票数 1

我正在尝试使用c#从oracle数据库中获取数据。我使用的是System.Data.OracleClient.dll,但是因为它已经过时了,所以我决定将其改为System.Data.Oledb。我的连接:

代码语言:javascript
复制
connection = new OleDbConnection();
connection.ConnectionString = string.Format("Provider=OraOLEDB.Oracle;Data Source={0};User ID={1};Password=23};", source, user, password);

下面是我获取数据的方法:

代码语言:javascript
复制
public ContactInfo GetInfo(string telnr)
    {
        connection.Open();
        Console.WriteLine("OracleState: {0}", connection.State);
        OleDbCommand command = connection.CreateCommand();
        string sql = @"Select t1.bed_bedrijfsnr
                      , t1.pers_persoonsnr
                      , REPLACE(REPLACE(REPLACE(REPLACE(t1.telefoonnr, ' ', ''), '-', ''), '(', ''), ')', '') as telnr
                      , REPLACE(REPLACE(REPLACE(REPLACE(t1.gsmnr, ' ', ''), '-', ''), '(', ''), ')', '') as gsmnr
                      , t1.e_mail
                      , t2.synoniem
                      , t2.sales_coordinator
                    From table1 t1
                      , table2 t2
                    Where t1.bed_bedrijfsnr = t2.bedrijfsnr
                    And (REPLACE(REPLACE(REPLACE(REPLACE(t1.telefoonnr, ' ', ''), '-', ''), '(', ''), ')', '') = :tel Or REPLACE(REPLACE(REPLACE(REPLACE(t1.gsmnr, ' ', ''), '-', ''), '(', ''), ')', '') = :tel);";
        command.CommandText = sql;
        command.Parameters.Add(new OleDbParameter(":tel", telnr));

        ContactInfo c = null;
        OleDbDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            //readdata
        }
        reader.Close();
        connection.Close();
        Console.WriteLine("Oracle State: {0}", connection.State);
        return c;
    }

当我将sql语句更改为"Select * from table1“时,它起作用了,但在此语句中,visual studio在'OleDbDataReader reader = command.ExecuteReader();‘上显示'OledbException row-00001无法分配内存’。

EN

回答 1

Stack Overflow用户

发布于 2015-09-10 03:35:46

我不确定为什么它会生成那个特定的错误,但是当您使用Parameters.Add时,它似乎不会替换多个参数实例。

由于在SQL语句中使用了两次":tel“,因此需要使用Parameters.Add两次。如果您重用相同的参数名称,它似乎工作得很好,但我还是重命名了我的参数名称。

代码语言:javascript
复制
string sql = @"Select t1.bed_bedrijfsnr
                  , t1.pers_persoonsnr
                  , REPLACE(REPLACE(REPLACE(REPLACE(t1.telefoonnr, ' ', ''), '-', ''), '(', ''), ')', '') as telnr
                  , REPLACE(REPLACE(REPLACE(REPLACE(t1.gsmnr, ' ', ''), '-', ''), '(', ''), ')', '') as gsmnr
                  , t1.e_mail
                  , t2.synoniem
                  , t2.sales_coordinator
                From table1 t1
                  , table2 t2
                Where t1.bed_bedrijfsnr = t2.bedrijfsnr
                And (REPLACE(REPLACE(REPLACE(REPLACE(t1.telefoonnr, ' ', ''), '-', ''), '(', ''), ')', '') = :tel1 Or REPLACE(REPLACE(REPLACE(REPLACE(t1.gsmnr, ' ', ''), '-', ''), '(', ''), ')', '') = :tel2);";
command.CommandText = sql;
command.Parameters.Add(new OleDbParameter(":tel1", telnr));
command.Parameters.Add(new OleDbParameter(":tel2", telnr));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32331841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档