These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Very strange error with DateTime
PostPosted: Sun Mar 04, 2007 12:23 am 
Newbie

Joined: Mon Jan 01, 2007 11:33 pm
Posts: 10
NHibernate. 1.2
SQL Server 2005 Express, set to be SQL Server 200 compatible
.Net v2.0.50727


I'm setting up an affiliate system and have decided to use the last day of the month as the date for each invoice, for example: "3/31/2007 11:59:59 PM".

What I've found is that if I query based upon "3/31/2007 11:59:59 PM" I get an invalid format exception. Note that I can do "5/31/2007 11:59:59 PM"(Note the change in month) without throwing the exception. I can also do "3/31/2007 11:59:58 PM"(Note the change in seconds) and it will work without throwing the exception.

However, it seems that last second causes it to throw.

Here is an excerpt of the code I used to test this:

Code:
query_string = "from Mega.Invoice t where month_ending_date = ? and affiliate_id= ?";

NHibernate.IQuery query = sess.CreateQuery(query_string);

query.SetString(0, "3/31/2007 11:59:59 PM");
query.SetString(1, aff_id.ToString());



Here is the full stack trace
Code:
[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2753235
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +102
   System.String.System.IConvertible.ToInt32(IFormatProvider provider) +43
   System.Convert.ToInt32(Object value) +25
   NHibernate.Type.Int32Type.Get(IDataReader rs, Int32 index) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Type\Int32Type.cs:29
   NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Type\NullableType.cs:270
   NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Type\NullableType.cs:212
   NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[] names, ISessionImplementor session, Object owner) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Type\AbstractType.cs:128
   NHibernate.Loader.Loader.Hydrate(IDataReader rs, Object id, Object obj, ILoadable persister, ISessionImplementor session, String[][] suffixedPropertyColumns) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Loader\Loader.cs:1101
   NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, Object obj, Type instanceClass, EntityKey key, LockMode lockMode, ILoadable rootPersister, ISessionImplementor session) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Loader\Loader.cs:1000
   NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Loader\Loader.cs:957
   NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Loader\Loader.cs:891
   NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Loader\Loader.cs:295
   NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Loader\Loader.cs:424
   NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Loader\Loader.cs:183
   NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Loader\Loader.cs:1751

[ADOException: could not execute query[SQL: select invoice0_.id as id7_, invoice0_.affiliate_id as affiliate2_7_, invoice0_.total as total7_, invoice0_.unique_hits as unique4_7_, invoice0_.signups as signups7_, invoice0_.month_ending_date as month6_7_, invoice0_.payment_method as payment7_7_, invoice0_.payment_date as payment8_7_, invoice0_.payment_verified_date as payment9_7_ from AFF_invoices invoice0_ where (month_ending_date=?)and(affiliate_id=?)]]
   NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Loader\Loader.cs:1761
   NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Loader\Loader.cs:1699
   NHibernate.Hql.Classic.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Hql\Classic\QueryTranslator.cs:1008
   NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Impl\SessionImpl.cs:1807
   NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters) in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Impl\SessionImpl.cs:1770
   NHibernate.Impl.QueryImpl.List() in C:\Documents and Settings\mreiland\Desktop\NHibernate2\src\NHibernate\Impl\QueryImpl.cs:57
   InvoiceDAL.load_invoices(Int32 aff_id, DateTime pFrom, DateTime pTo, ISession sess) in e:\MegaWork\megainternet\Affiliate\App_Code\invoiceDAL.cs:87
   InvoiceDAL.load_invoice(Int32 aff_id, Int32 _month, Int32 _year, ISession sess) in e:\MegaWork\megainternet\Affiliate\App_Code\invoiceDAL.cs:31
   test.Page_Load(Object sender, EventArgs e) in e:\MegaWork\megainternet\Affiliate\test.aspx.cs:20
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061




If someone could give me a nudge in the right direction I would appreciate it. I'm completely at a loss to explain this behavior. If you need more info please let me know.


Thank You,
Michael


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 04, 2007 6:41 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
The problem you are experiencing is normally related to the collation setting of the database you're working with.

You might want to try locally parsing the date/time string to a DateTime object and then use SetDateTime instead of SetString - that way you won't be at the mercy of the database system's interpretation of the string.

Hope that helps.

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 1:39 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
My experience with SQL Server and date formats is to pass dates in american format to the SQL Server. This format is always recognized correct regardless of the language or collation settings.

Regards
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 2:00 am 
Newbie

Joined: Mon Jan 01, 2007 11:33 pm
Posts: 10
merge that solved the problem. I wasn't aware of the data type specific methods for setting query variables. I'm still learning the in's and out's of NHibernate so thank you.


luedi I'll keep that in mind.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.