Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# OLEDBEException行-00001无法分配内存_C#_Sql_Oracle_Oledb - Fatal编程技术网

C# OLEDBEException行-00001无法分配内存

C# OLEDBEException行-00001无法分配内存,c#,sql,oracle,oledb,C#,Sql,Oracle,Oledb,我正在尝试使用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};", so

我正在尝试使用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语句更改为从表1中选择*时,它可以工作,但对于此语句,visual studio在“OleDbDataReader=command.ExecuteReader;”上显示“OLEDBEException row-00001无法分配内存”

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

因为在SQL语句中使用了:tel两次,所以需要使用参数。添加两次。如果重复使用相同的参数名,似乎效果不错,但我还是重命名了我的参数名

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

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

因为在SQL语句中使用了:tel两次,所以需要使用参数。添加两次。如果重复使用相同的参数名,似乎效果不错,但我还是重命名了我的参数名

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