【问题标题】:OledbException row-00001 cannot allocate memoryOledbException row-00001 无法分配内存
【发布时间】:2015-09-01 12:36:32
【问题描述】:

我正在尝试使用 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 语句更改为“从 table1 中选择 *”时,它可以工作,但使用此语句时,Visual Studio 会在“OleDbDataReader reader = command.ExecuteReader();”上显示“OledbException row-00001 无法分配内存”

【问题讨论】:

    标签: c# sql oracle oledb


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-17
      • 2017-07-15
      • 2015-08-15
      • 2015-04-01
      • 2017-12-05
      • 2016-06-03
      • 2018-04-09
      • 1970-01-01
      相关资源
      最近更新 更多