Strange exception.

Discussion in 'ASP .Net' started by =?Utf-8?B?TWF0dA==?=, Jul 3, 2007.

  1. I am using the PetShop example's ExecuteReader function:
    public static SqlDataReader ExecuteReader(string connectionString,
    CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    {....}

    However, I alwasy get the following exception:

    Outter exception:
    The type initializer for threw an exception.

    Inner exception:
    Object reference not set to an instance of an object.

    One of the calling is:

    SqlDataReader reader =
    SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction,
    CommandType.Text, SQL_SELECT_EVENTS_BETWEEN_DATES, null)

    Which SqlHelper.ConnectionStringLocalTransaction has a valid connection
    string, CommandType.Text is built-in type, SQL_SELECT_EVENTS_BETWEEN_DATES is
    a valid string constant SQL statement. I tried to pass valid parameters too
    and got the same exception?
    =?Utf-8?B?TWF0dA==?=, Jul 3, 2007
    #1
    1. Advertising

  2. Matt,

    Judging on the error description it looks like static constructor or the
    class or initializer of one of it's static variables causes the error and not
    that specific method - calling this method causes the class type to
    instantiate in memory.

    HTH

    "Matt" wrote:

    > I am using the PetShop example's ExecuteReader function:
    > public static SqlDataReader ExecuteReader(string connectionString,
    > CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    > {....}
    >
    > However, I alwasy get the following exception:
    >
    > Outter exception:
    > The type initializer for threw an exception.
    >
    > Inner exception:
    > Object reference not set to an instance of an object.
    >
    > One of the calling is:
    >
    > SqlDataReader reader =
    > SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction,
    > CommandType.Text, SQL_SELECT_EVENTS_BETWEEN_DATES, null)
    >
    > Which SqlHelper.ConnectionStringLocalTransaction has a valid connection
    > string, CommandType.Text is built-in type, SQL_SELECT_EVENTS_BETWEEN_DATES is
    > a valid string constant SQL statement. I tried to pass valid parameters too
    > and got the same exception?
    >
    >
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Jul 3, 2007
    #2
    1. Advertising

  3. I use the file SQLHelper.cs the way exactly as the PetShop 4.

    SQLHelper.cs:

    namespace PetShop.DBUtility {
    public abstract class SqlHelper {
    .......
    public static SqlDataReader ExecuteReader(string connectionString,
    CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    {
    SqlCommand cmd = new SqlCommand();
    SqlConnection conn = new SqlConnection(connectionString);

    try {
    PrepareCommand(cmd, conn, null, cmdType, cmdText,
    commandParameters);
    SqlDataReader rdr =
    cmd.ExecuteReader(CommandBehavior.CloseConnection);
    cmd.Parameters.Clear();
    return rdr;
    }
    catch {
    conn.Close();
    throw;
    }
    }
    ......
    }

    "Sergey Poberezovskiy" wrote:

    > Matt,
    >
    > Judging on the error description it looks like static constructor or the
    > class or initializer of one of it's static variables causes the error and not
    > that specific method - calling this method causes the class type to
    > instantiate in memory.
    >
    > HTH
    >
    > "Matt" wrote:
    >
    > > I am using the PetShop example's ExecuteReader function:
    > > public static SqlDataReader ExecuteReader(string connectionString,
    > > CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    > > {....}
    > >
    > > However, I alwasy get the following exception:
    > >
    > > Outter exception:
    > > The type initializer for threw an exception.
    > >
    > > Inner exception:
    > > Object reference not set to an instance of an object.
    > >
    > > One of the calling is:
    > >
    > > SqlDataReader reader =
    > > SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction,
    > > CommandType.Text, SQL_SELECT_EVENTS_BETWEEN_DATES, null)
    > >
    > > Which SqlHelper.ConnectionStringLocalTransaction has a valid connection
    > > string, CommandType.Text is built-in type, SQL_SELECT_EVENTS_BETWEEN_DATES is
    > > a valid string constant SQL statement. I tried to pass valid parameters too
    > > and got the same exception?
    > >
    > >
    =?Utf-8?B?TWF0dA==?=, Jul 3, 2007
    #3
  4. Matt,

    I do not beleive that you can step into this method while debugging, do you?
    As I mentioned in my previous post, I has this type of exception when the
    class static constructor throws an error - so seeing the method code does not
    help much :-(

    If you can post the class constructor (in case one is present) and all
    static initializers, such as following:
    private static object _myCustom = new Custom();

    Alternatively, if you can post here the link to download the petshot
    application, I will try to investigate it further - otherwise there is not
    enough info for me to make any conclusions...

    I would prefer the first option though - less time for me :)


    "Matt" wrote:

    > I use the file SQLHelper.cs the way exactly as the PetShop 4.
    >
    > SQLHelper.cs:
    >
    > namespace PetShop.DBUtility {
    > public abstract class SqlHelper {
    > ......
    > public static SqlDataReader ExecuteReader(string connectionString,
    > CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    > {
    > SqlCommand cmd = new SqlCommand();
    > SqlConnection conn = new SqlConnection(connectionString);
    >
    > try {
    > PrepareCommand(cmd, conn, null, cmdType, cmdText,
    > commandParameters);
    > SqlDataReader rdr =
    > cmd.ExecuteReader(CommandBehavior.CloseConnection);
    > cmd.Parameters.Clear();
    > return rdr;
    > }
    > catch {
    > conn.Close();
    > throw;
    > }
    > }
    > .....
    > }
    >
    > "Sergey Poberezovskiy" wrote:
    >
    > > Matt,
    > >
    > > Judging on the error description it looks like static constructor or the
    > > class or initializer of one of it's static variables causes the error and not
    > > that specific method - calling this method causes the class type to
    > > instantiate in memory.
    > >
    > > HTH
    > >
    > > "Matt" wrote:
    > >
    > > > I am using the PetShop example's ExecuteReader function:
    > > > public static SqlDataReader ExecuteReader(string connectionString,
    > > > CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    > > > {....}
    > > >
    > > > However, I alwasy get the following exception:
    > > >
    > > > Outter exception:
    > > > The type initializer for threw an exception.
    > > >
    > > > Inner exception:
    > > > Object reference not set to an instance of an object.
    > > >
    > > > One of the calling is:
    > > >
    > > > SqlDataReader reader =
    > > > SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction,
    > > > CommandType.Text, SQL_SELECT_EVENTS_BETWEEN_DATES, null)
    > > >
    > > > Which SqlHelper.ConnectionStringLocalTransaction has a valid connection
    > > > string, CommandType.Text is built-in type, SQL_SELECT_EVENTS_BETWEEN_DATES is
    > > > a valid string constant SQL statement. I tried to pass valid parameters too
    > > > and got the same exception?
    > > >
    > > >
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Jul 4, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. EP
    Replies:
    0
    Views:
    502
  2. =?Utf-8?B?Sm9oYW4gTmVpZGVubWFyaw==?=

    Strange exception

    =?Utf-8?B?Sm9oYW4gTmVpZGVubWFyaw==?=, Aug 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    411
    Paul Glavich [MVP - ASP.NET]
    Aug 24, 2004
  3. Kevin Spencer

    Strange Exception with WebMethod

    Kevin Spencer, Oct 25, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    422
    Kevin Spencer
    Oct 28, 2004
  4. Federico
    Replies:
    0
    Views:
    359
    Federico
    Oct 22, 2003
  5. Harvey Twyman
    Replies:
    8
    Views:
    549
    August Derleth
    Oct 25, 2003
Loading...

Share This Page