RE: Problem with profiling datetime



Martin Masse (MartinMasse@xxxxxxxxxxxxxxxxxxxxxxxxx) writes:
I will add a sample....since my initial post is not that clear...

That simple .NET code

SqlCommand cmd = new SqlCommand("select @TestDate");
cmd.Parameters.AddWithValue("@TestDate", DateTime.Now);
cmd.Connection = conn;
DateTime dt = (DateTime) cmd.ExecuteScalar();

The resulting trace log item is as follow

exec sp_executesql N'select @TestDate',N'@TestDate
datetime',@TestDate=''2006-04-02 18:44:22:687''

Wich will fail when analyzed since there is a syntax error in the command
e.g. two single quote at the end and start of the date.

Please help!

I don't really have a suggestion how to work around this, as I have not
worked much with the DTA.

However, it is obviously a bug somewhere, although I can't tell whether
it is in SQL Trace, the Profiler or in SqlClient. Nevertheless I took
the liberty to submit a bug for it on the MSDN Product Feedback Cetnre,
http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackId=F
DBK48153

What I noticed was that if I changed DateTime.Now to "DateTime.Now",
that is a string, I got the correct output in Profiler.

--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: trouble porting a trivially simple function - with declared variables
    ... CREATE FUNCTION my_max_market_date RETURNS datetime ... DECLARE @mmmd AS datetime; ... SQL Server comes with an extensive Online documentation, ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Real to datetime - how to...?
    ... would like to have it in hh:mm:ss format. ... The division with 24 is necessary, because a datetime value consists ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: call a function using ado
    ... > excel vba. ... > declare @RetVal datetime ... very ineffectient to me to SQL Server for such a thing. ... Books Online for SQL Server 2005 at ...
    (microsoft.public.data.oledb)
  • Re: datetime
    ... > Your column is defined as datetime datatype and you have a default ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: stored proc bug with datetime variable
    ... @DATE_RANGE_START as datetime, ... declare @DATE_RANGE_START datetime ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)