PgSqlDataReader throwing a System.NullReferenceException

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
jhopper
Posts: 2
Joined: Thu 19 Feb 2009 22:16

PgSqlDataReader throwing a System.NullReferenceException

Post by jhopper » Thu 19 Feb 2009 22:50

We have been receiving errors such as the following within our log4net logs only in our production environment.

Code: Select all

System.NullReferenceException: Object reference not set to an instance of an object.
   at Devart.Data.PostgreSql.PgSqlDataReader.a(q[] A_0)
   at Devart.Data.PostgreSql.PgSqlDataReader.e(Int32 A_0)
   at Devart.Data.PostgreSql.PgSqlCommand.InternalExecute(CommandBehavior behavior, IDisposable stmt, Int32 startRecord, Int32 maxRecords)
   at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
   at Vetstreet.Hd.Data.Command.ExecuteReader()
   at Vetstreet.Hd.Core.Data.LocationInfoData.GetLocationInfo(Int32 locationId)
This method is called from the HttpModule on every page load, but this error message is only received intermittently. We have not been able to prove this, but this only seems to happen after an undetermined period of inactivity. Meaning our production site normally works fine.

Also note that another database call successfully happens just prior to this call, though it is an ExecuteNonQuery. I know this is successful because the output parameters are used by the method mentioned in the error.

We have 4 environments, but we are experiencing this error only on our production environment.

Appreciate your help in troubleshooting this error. We suspect a configuration difference in production, but any suggestions on what to check are appreciated.

we are using:
Devart.Data: 5.0.1.0
Devart.Data.PostgreSql: 4.0.12.0
PostgreSQL 8.3

The C# method calling the db function

Code: Select all

  public static LocationInfo GetLocationInfo(int locationId)
        {
            LocationInfo info = new LocationInfo();

            IDataReader dr = null;
            IDbTransaction tn = null;
            using (Connection cn =new Connection())
            using (Command cmd = new Command("hd.get_hdlocs", cn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("in_hdloc_id", locationId);

                try
                {
                    cn.Open();
                    tn = cn.BeginTransaction();
                    dr = cmd.ExecuteReader();

                    if (dr.Read())
                    {
                        info.Address1 = Helpers.GetString(dr["address1"]);
                        //. . .Other Object Assignments . . .//
                    }
                    dr.Close();
                }
                catch (Exception ex)
                {
                    log.Error("Error in GetLocationInfo calling stored procedure hd.get_hdlocs for location id " + locationId.ToString(), ex);
                }
                finally
                {
                    if (tn != null)
                        tn.Commit(); // only a get proc, so just commit
                    if (cn.State != ConnectionState.Closed)
                        cn.Close();
                }
                
            }
            
            return info;
        }
The db function

Code: Select all

CREATE OR REPLACE FUNCTION hd.get_hdlocs(in_hdloc_id integer)
  RETURNS SETOF refcursor AS
$BODY$
declare
         v_ref1 refcursor;
 begin
 
         open v_ref1 for 
         [select statement]

 return next v_ref1;
 
 exception
         when others then
                 raise notice 'hd.get_hdlocs failed - % (%)',SQLERRM,SQLSTATE;
                 return;
 end;
 $BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION hd.get_hdlocs(integer) OWNER TO ----;
Thanks for the help,
Jeff

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Wed 25 Feb 2009 12:10

Hello,

We cannot find your e-mail address from registered users' e-mails. Could you please send me (alexsh*devart*com) your license number and the registration name. We will make a special build (with some modifications) of your license edition and send you it by e-mail to check if it helps.

Best regards.

jhopper
Posts: 2
Joined: Thu 19 Feb 2009 22:16

DB team has corrected this issue

Post by jhopper » Thu 26 Feb 2009 18:45

Shalex, thank you for the response.

Seems there was some database issue that was causing our problem. The DB team has made some changes and we are no longer experiencing this error.

I did not hear the specifics of what they had changed, but will pass those along if they ever share with a "lowly" developer.

Thanks again,
Jeff

Post Reply