Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Strange exception.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Matt - 03 Jul 2007 07:30 GMT
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?
Sergey Poberezovskiy - 03 Jul 2007 08:32 GMT
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

> I am using the PetShop example's ExecuteReader function:
>         public static SqlDataReader ExecuteReader(string connectionString,
[quoted text clipped - 19 lines]
> a valid string constant SQL statement. I tried to pass valid parameters too
> and got the same exception?
Matt - 03 Jul 2007 15:10 GMT
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;
           }
       }
.....
}

> Matt,
>
[quoted text clipped - 28 lines]
> > a valid string constant SQL statement. I tried to pass valid parameters too
> > and got the same exception?
Sergey Poberezovskiy - 04 Jul 2007 02:40 GMT
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 :-)

> I use the file SQLHelper.cs the way exactly as the PetShop 4.
>
[quoted text clipped - 57 lines]
> > > a valid string constant SQL statement. I tried to pass valid parameters too
> > > and got the same exception?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.