oledbeexception row-00001无法分配内存

本文关键字:分配 内存 row-00001 oledbeexception | 更新日期: 2023-09-27 18:10:45

我正在尝试使用c#从oracle数据库获取数据。我使用的是System.Data.OracleClient.dll,但由于这是过时的,我决定将其更改为System.Data.Oledb。我的连接:

connection = new OleDbConnection();
connection.ConnectionString = string.Format("Provider=OraOLEDB.Oracle;Data Source={0};User ID={1};Password=23};", source, user, password);

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

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说'OledbException row-00001不能分配内存'上'OleDbDataReader reader = command.ExecuteReader();'

oledbeexception row-00001无法分配内存

我不知道为什么它会产生特定的错误,但当你使用参数。添加它似乎不能替代多个参数实例。

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

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));