The following bug has been logged online:
Bug reference: 2044
Logged by: balamuralikn
Email address: balamuralikn@rediffmail.com
PostgreSQL version: 8.0.4
Operating system: Win 2000
Description: OLEDB Driver error
Details:
iam facing the following error on execution of the given c# code using
pgoledb driver 1.0.0.19
Error :
---------
F:\CSharpTest\OLEDBTest>customermanager
Befor ExecuteReader
OleDb Exception System.Data.OleDb.OleDbException: No error information
availab
le: 0x80040155.
at System.Data.OleDb.OleDbDataReader.ProcessResults(Int32 hr)
at System.Data.OleDb.OleDbDataReader.NextResult()
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
beh
avior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior
behavior)
at Customer.FindByName(String strName)
Source Code:( File - CustomerManager.cs)
------------------------------------------
using System;
using System.Data.OleDb;
public class Customer{
string strName;
string strAddr;
String strCon = "Provider=PostgreSQL OLE DB Provider;Password=relax;User
ID=postgres; Data Source=anu;Location=test;Extended Properties=";
// String strCon = "Provider=SQLOLEDB;User
ID=sa;pwd=;Server=anu;Database=test";
OleDbConnection con ;
public Customer(){
con = new OleDbConnection(strCon);
con.Open();
}
public String Name{
get {
return strName;
}
set {
strName = value;
}
}
public String Address{
get {
return strAddr;
}
set {
strAddr = value;
}
}
public void Add() {
String strInsert = "Insert into customers (Name, Address) values (";
strInsert += "'" +Name +"', ";
strInsert += "'" +Address +"')";
OleDbCommand cmd = new OleDbCommand(strInsert);
cmd.Connection = con;
cmd.ExecuteNonQuery();
}
public Customer FindByName(String strName) {
try{
String strSql = "Select * from Customers where Name = '"+ strName +
"'";
OleDbCommand cmd = new OleDbCommand(strSql, con);
Console.WriteLine("Befor ExecuteReader");
OleDbDataReader objReader =
cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
Console.WriteLine("Befor 'Read'");
if (objReader.Read()){
Console.WriteLine("After 'Read'");
Name = objReader.GetString(0);
Address = objReader.GetString(1);
Console.WriteLine("After 'Fetch'");
}
else{
throw new Exception("Customer not found");
}
}catch(OleDbException e){
Console.WriteLine("OleDb Exception " +e);
throw e;
}catch(Exception e){
Console.WriteLine("Application Exception " +e);
throw e;
}
return this;
}
};
public class CustomerManager{
public static void Main(String [] a){
/* //Test for adding new customer - perfectly working with postgre
if (a.Length > 0){
try{
Customer cust = new Customer();
cust.Name = a[0];
cust.Address = a[1];
cust.Add();
Console.WriteLine("Sucess");
}catch(Exception e){
Console.WriteLine("Error : " + e);
}
}
else{
Console.WriteLine("Invalid arguments");
} */
// Test for finding customer - not working with postgre
try{
Customer cust = new Customer() ;
cust = cust.FindByName("Murali");
Console.WriteLine("Name : " + cust.Name);
Console.WriteLine("Address : " + cust.Address);
}catch(OleDbException ex){
// Console.WriteLine("Data Error :"+ ex.StackTrace);
}catch(Exception ex){
// Console.WriteLine("Application Error :"+ ex.StackTrace);
}
}
};