Note that there are some explanatory texts on larger screens.

plurals
  1. POdatetime conversion on sql server stopped working
    primarykey
    data
    text
    <p>I am puzzled by an error that came out of the blue yesterday on my production server. I am doing a LINQ2SQL query such as:</p> <pre><code>var mis = from m in dtcx.valori join p in dtcx.TEPARAMs on m.PARAMCD equals p.PARAMCD where blah blah blah select new { dataRilevazione = m.dataRilevazione, id =m.data&gt;=new DateTime(2010,02,26)&amp;&amp;m.X==3&amp;&amp;m.Y==69?100: m.id, blah blha }; </code></pre> <p>this converts into SQL query which has the condition:</p> <pre><code>N'SELECT [t0].[dataRilevazione], (CASE WHEN ([t0].[data] &gt;= @p6) AND ([t0].[X] = @p7) AND ([t0].[Y] = @p8) THEN @p9 </code></pre> <p>with </p> <p><code>@p6='2010-02-26 00:00:00'</code></p> <p>this has worked like a charm for ages, since two days ago when it stopped working saying that there was a wrong conversion from varchar to datetime.</p> <p>as a matter of fact the problem is that 2010-02-26 00:00:00 is no more converted to a date! if I try </p> <p>print </p> <pre><code>convert(datetime,'2010-02-26 00:00:00' ) </code></pre> <p>I get the same error, which disappears using </p> <pre><code>convert(datetime,'2010-02-26 00:00:00', datetime) </code></pre> <p>since when all worked I did not change the user, nor its locale, nor anything that I am aware of.</p> <p>what can I do? thanks</p> <p><em><strong>UPDATE:</em></strong> profiling SQL Server, linq 2 sql seems to set the correct language:</p> <pre><code>-- network protocol: TCP/IP set quoted_identifier on set arithabort off set numeric_roundabort off set ansi_warnings on set ansi_padding on set ansi_nulls on set concat_null_yields_null on set cursor_close_on_commit off set implicit_transactions off set language us_english set dateformat mdy set datefirst 7 set transaction isolation level read committed </code></pre> <p><strong>so the language is set to us_english!</strong> Why the conversion still fails is beyond me! Every idea is appreciated...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload