As it is the syntax of the handling of execution of cursors in NET since it leaves syntax error to me surrounds to all and I have asi.
pgcoman.CommandText=("fetch all in \"ref\"");
error syntax NET
Such code works ok in my tests. Please make sure that you open and fetch cursor in the same transaction.
PgSqlCommand cursorCmd = new PgSqlCommand("fetch all in \"dept\"", pgSqlConnection);
// need to start transaction, because cursor is acessible only in transaction
PgSqlTransaction tr = pgSqlConnection.BeginTransaction();
try{
try {
....
// Opens named cursor
....
// fetch data from named cursor
PgSqlDataReader dataReader = cursorCmd.ExecuteReader();
while (dataReader.Read()) {
object obj = dataReader.GetValue(0);
recCount++;
}
dataReader.Close();
}
finally{
// commit transaction
tr.Commit();
}
PgSqlCommand cursorCmd = new PgSqlCommand("fetch all in \"dept\"", pgSqlConnection);
// need to start transaction, because cursor is acessible only in transaction
PgSqlTransaction tr = pgSqlConnection.BeginTransaction();
try{
try {
....
// Opens named cursor
....
// fetch data from named cursor
PgSqlDataReader dataReader = cursorCmd.ExecuteReader();
while (dataReader.Read()) {
object obj = dataReader.GetValue(0);
recCount++;
}
dataReader.Close();
}
finally{
// commit transaction
tr.Commit();
}