dbTalk Databases Forums  

Strange error while executing query

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss Strange error while executing query in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
=?Utf-8?B?cnZhbmdlbGRyb3A=?=
 
Posts: n/a

Default Strange error while executing query - 08-13-2007 , 09:06 AM






Hi,

I have an unexpected error while executing the query below

If I run it in Management Studio it will work fine, but if I run it using my
code in C# on the same machine it will fail with the following exception:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999
11:59:59 PM

I use 'System.Data.SqlClient.SqlCommand' and execute the query using
'ExecuteNonQuery'.

It fails because it wants to insert getdate(). If I replace getdate() with
NULL it works. If I then run an extra update query using a parameter with the
correct date in it, this will work too. I do have systems however, that
accept the original query.

How can this be and how can make it work?

Query:
insert into accounthistory
(UserInfoUserName,AccountInfoStatus,AccountInfoAct ive,AccountInfoHasDigiNotarKey,AccountInfoDigiNota rKeyIsStored,AccountInfoUsedSize,AccountInfoMaxVer sions,AccountTypeID,AccountInfoOwnerID,AccountInfo StartDate,AccountInfoDigiNotarKey,AccountInfoDigiN otarKeyHash,AccountInfoTrialUser,AccountInfoChange dBy,AccountInfoUserProfileTypeID)
select
UserInfoUserName,AccountInfoStatus,AccountInfoActi ve,AccountInfoHasDigiNotarKey,AccountInfoDigiNotar KeyIsStored,AccountInfoUsedSize,AccountInfoMaxVers ions,AccountTypeID,AccountInfoOwnerID,getdate(),Ac countInfoDigiNotarKey,AccountInfoDigiNotarKeyHash, AccountInfoTrialUser,AccountInfoChangedBy,AccountI nfoUserProfileTypeID from AccountInfo with (READUNCOMMITTED) where userinfousername=@0

Reply With Quote
  #2  
Old   
=?utf-8?Q?Ekrem_=C3=96nsoy?=
 
Posts: n/a

Default Re: Strange error while executing query - 08-29-2007 , 05:06 PM






Hello!

How about using a variable and assign "today.date" value to that variable in
c# and use this variable as a parameter in your query code?

--
Ekrem Önsoy




"rvangeldrop" <rvangeldrop (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi,

I have an unexpected error while executing the query below

If I run it in Management Studio it will work fine, but if I run it using
my
code in C# on the same machine it will fail with the following exception:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999
11:59:59 PM

I use 'System.Data.SqlClient.SqlCommand' and execute the query using
'ExecuteNonQuery'.

It fails because it wants to insert getdate(). If I replace getdate() with
NULL it works. If I then run an extra update query using a parameter with
the
correct date in it, this will work too. I do have systems however, that
accept the original query.

How can this be and how can make it work?

Query:
insert into accounthistory
(UserInfoUserName,AccountInfoStatus,AccountInfoAct ive,AccountInfoHasDigiNotarKey,AccountInfoDigiNota rKeyIsStored,AccountInfoUsedSize,AccountInfoMaxVer sions,AccountTypeID,AccountInfoOwnerID,AccountInfo StartDate,AccountInfoDigiNotarKey,AccountInfoDigiN otarKeyHash,AccountInfoTrialUser,AccountInfoChange dBy,AccountInfoUserProfileTypeID)
select
UserInfoUserName,AccountInfoStatus,AccountInfoActi ve,AccountInfoHasDigiNotarKey,AccountInfoDigiNotar KeyIsStored,AccountInfoUsedSize,AccountInfoMaxVers ions,AccountTypeID,AccountInfoOwnerID,getdate(),Ac countInfoDigiNotarKey,AccountInfoDigiNotarKeyHash, AccountInfoTrialUser,AccountInfoChangedBy,AccountI nfoUserProfileTypeID
from AccountInfo with (READUNCOMMITTED) where userinfousername=@0


Reply With Quote
  #3  
Old   
=?Utf-8?B?cnZhbmdlbGRyb3A=?=
 
Posts: n/a

Default Re: Strange error while executing query - 08-30-2007 , 03:32 AM



Hello Ekrem,

Thank you for your reply. I am using the workaround you are suggesting, but
I find it a hack and my question is more about why my C# executed query
fails, while the same query in Management Studie Query Editor succeeds on the
same machine.

Any ideas?

Kind regards,

"Ekrem Önsoy" wrote:

Quote:
Hello!

How about using a variable and assign "today.date" value to that variable in
c# and use this variable as a parameter in your query code?

--
Ekrem Önsoy




"rvangeldrop" <rvangeldrop (AT) discussions (DOT) microsoft.com> wrote in message
news:56D73326-6B9B-482A-9D76-55162DE6E1DB (AT) microsoft (DOT) com...
Hi,

I have an unexpected error while executing the query below

If I run it in Management Studio it will work fine, but if I run it using
my
code in C# on the same machine it will fail with the following exception:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999
11:59:59 PM

I use 'System.Data.SqlClient.SqlCommand' and execute the query using
'ExecuteNonQuery'.

It fails because it wants to insert getdate(). If I replace getdate() with
NULL it works. If I then run an extra update query using a parameter with
the
correct date in it, this will work too. I do have systems however, that
accept the original query.

How can this be and how can make it work?

Query:
insert into accounthistory
(UserInfoUserName,AccountInfoStatus,AccountInfoAct ive,AccountInfoHasDigiNotarKey,AccountInfoDigiNota rKeyIsStored,AccountInfoUsedSize,AccountInfoMaxVer sions,AccountTypeID,AccountInfoOwnerID,AccountInfo StartDate,AccountInfoDigiNotarKey,AccountInfoDigiN otarKeyHash,AccountInfoTrialUser,AccountInfoChange dBy,AccountInfoUserProfileTypeID)
select
UserInfoUserName,AccountInfoStatus,AccountInfoActi ve,AccountInfoHasDigiNotarKey,AccountInfoDigiNotar KeyIsStored,AccountInfoUsedSize,AccountInfoMaxVers ions,AccountTypeID,AccountInfoOwnerID,getdate(),Ac countInfoDigiNotarKey,AccountInfoDigiNotarKeyHash, AccountInfoTrialUser,AccountInfoChangedBy,AccountI nfoUserProfileTypeID
from AccountInfo with (READUNCOMMITTED) where userinfousername=@0



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.