Running the same query causing error the second time

Viewed 903

I have a Data-table with all the mandatory fields which is required by select query in it. Now i am fetching data from 1st row of the data-table and running a select query (as given below). For the first time its working fine. Now I am taking the 2nd row and giving all the mandatory fields (as i did for the first) and running the select query its giving error "insufficient permissions". When i am running both the select query (which are actually same but with different parameter) manually in Oracle SQL Developer its working fine.

Query1: select cloumnname1 from table where columnname2='valueA' and columnname3= 'VALUEB'
Query2: select cloumnname1 from table where columnname2='valueA' and columnname3= 'VALUEB'

To fetch data from database

public OracleDataReader ExecuteReader(string SelectQuery, string conString)
        {
        try
        {
            OpenDbConnection(conString);

            OracleCommand cmd = new OracleCommand();
            cmd.Connection = con;
            cmd.CommandText = SelectQuery;
            cmd.CommandType = System.Data.CommandType.Text;
            OracleDataReader ora_dataReader = cmd.ExecuteReader();

            return ora_dataReader;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
        }
    }

EDIT: Forgot to mention that i am calling this funtion in another function as given below

public DataTable GetDataFromDB(string SelectQuery, string conString)
        {
            try
            {
                DataTable dt = new DataTable();
                dt.Load(ExecuteReader(SelectQuery,conString));

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                CloseDbConnection();
            }
        }
3 Answers
Related