SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


The conversion of a char data type to a datetime data type resulted in an out-of-range datetime...


The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Author
Message
Ramalingam S
Ramalingam S
SSC Veteran
SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)

Group: General Forum Members
Points: 244 Visits: 57
Hi All,

We have developed a web appln using ASP.Net 2.0 / Sql Server 2005. In a web form, while inserting a value into a date field , I am getting the following error.

"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated."

We are sending the value in MM/DD/YYYY format from the application.This works in my development environment but not in the production server.

The language assigned to the Sqluser is "English" in both the cases. We don't have access to the production server.

What could be the problem? Kindly throw some light on this.

Thanks in advance
Roshan Jospeh
Roshan Jospeh
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1629 Visits: 2087
try
convert(datetime,'date',101)

----------------------------------------------------------------------------------------------------------------------------------------------------
Roshan Joe

Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help
Ramalingam S
Ramalingam S
SSC Veteran
SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)SSC Veteran (244 reputation)

Group: General Forum Members
Points: 244 Visits: 57
Hi,

Thanks for u'r quick reply.

I think you have understood differently. My problem is "while inserting , i am getting the sql exception". But this is happening only in production server.

I can't use the convert function because, i have around 50 pages in my application and have to use this convert function everywhere.

Since it is working in my local server, I think this problem is due to some server settings.

Please tell me where to change this settings...
Roshan Jospeh
Roshan Jospeh
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1629 Visits: 2087
Please see the below link

http://support.microsoft.com/kb/173907

----------------------------------------------------------------------------------------------------------------------------------------------------
Roshan Joe

Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help
Florian Reischl
Florian Reischl
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3637 Visits: 3934
A hint for future projects and implementations...

Don't create dynamic SQL statements containing values in your font end. This enables SQL injection and causes problems as your current. Use parameterized statements and you cannot run into those problems.

[code="csharp"]
///=======================================================
// WRONG WAY
using (SqlConnection cn = new SqlConnection("MyConnectionString"))
{
cn.Open();

string statement = "INSERT INTO MyTable (Id, MyDateColumn) VALUES (1, '06/24/2009')";
using (SqlCommand cmd = new SqlCommand(statement, cn))
{
cmd.ExecuteNonQuery();
}
}

///=======================================================
// CORRECT WAY
using (SqlConnection cn = new SqlConnection("MyConnectionString"))
{
cn.Open();

string statement = "INSERT INTO MyTable (Id, MyDateColumn) VALUES (@Id, @MyDate)";
using (SqlCommand cmd = new SqlCommand(statement, cn))
{
SqlParameter paramId = cmd.Parameters.Add("@Id", SqlDbType.Int);
SqlParameter paramMyDate = cmd.Parameters.Add("@MyDate", SqlDbType.DateTime);

paramId.Value = 1;
paramMyDate.Value = DateTime.Now;

cmd.ExecuteNonQuery();
}
}
[/code]

Flo


The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
MMartin1
MMartin1
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2817 Visits: 2031
Your database login may have a default language different than English, or the production server's default language may not not match the one to your login. Maybe the agent for the job has another default language as well. Either way default languages may not be matching. It is thus best to always use the universal yyyymmdd string format for dates.

----------------------------------------------------
How to post forum questions to get the best help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search