[SQL Server] "syntax error occurred when converting string to datetime" SOLUTION

Source: Internet
Author: User
Found today
Microsoft ole db provider for SQL Server (0x80040e07)
A syntax error occurs when converting a string to datetime.
. Check the program and find that the current time obtained in the program uses now () and response. the write output indicates that "Morning" or "Afternoon" appears in the string, while the datetime (8) Type of the SQL Server database does not accept "Morning" or "Afternoon ", it cannot be automatically converted, so an error occurs. (If you try again, this will not happen in the ACCESS database ).
For example, insert into test (time) values ('2017-04-03 3:50:12 ') is automatically converted to the 24-hour format in access. The value is "2010 15:50:12 ". However, an error occurs in SQL Server, prompting "A syntax error occurred when converting a string to datetime. "This should be the problem of time format settings. Check the Internet and solve the problem through the following methods.

I. Windows XP solution (modify the registry, I have tested it successfully)

1. Control Panel-region and language options-set the time to the 24-hour format.
2. Create HKEY_LOCAL_MACHINE/software/Microsoft/oleaut/varconversionlocalesetting = 2 (DWORD)
Note: The oleaut item may not exist. If it does not exist, you must first create this item.
3. Restart IIS.
Solve the problem.
The principle is to force ASP time to use the region format.

Ii. Solution for Windows 2003 (modify region settings)

On the Control Panel → area settings → time style and date format settings:
Set the time style to HH: mm: Ss.
Set the short date format to yyyy-mm-dd.
(Win2003 does not need to modify the Registry. Someone has successfully tested it)

Iii. General Solutions (modified in the Program)

Replace can be used to replace the "Morning" or other unwanted characters...

For example, <% = Replace (now, "Morning", "") %>

Or replace all Chinese characters: Replace (now, "[/u4e00-/u9fa5]", "").

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.