views:

63

answers:

2

Hi, I developed an Asp.net application that uses Entity framework to connect to a Sql Server 2008(not R2) database.
The client run the db script against a Sql server 2008 R2 database and it executed successfully.
When the application is executed an exception is thrown:
'Sysutcdatetime' is not recognized as a built in function.
After checking the stack trace, it appeared that the exception is thrown when a LINQ to Entity framework statement is executed. The statement is something like this:

var item = Entities.News.FirstOrDefault(n => n.ExpirationDate > DateTime.UtcNow);

As far as I understand this, the generated sql statement from Entity framework uses the function Sysutcdatetime to get the current UTC date and time.
I know one of the solutions is to store the date in a variable than pass it to the lambda expression, that way the UTC date and time will be determined in the application level and hardcoded in the generated sql statement.

var currentUtcDate = DateTime.UtcNow;
var item = Entities.News.FirstOrDefault(n => n.ExpirationDate > currentUtcDate);

But I am curious why the function Sysutcdatetime exists in Sql server 2008 and not in Sql server 2008 R2 ?

+1  A: 
select Sysutcdatetime()
select @@VERSION

Just ran that on my SQL Server and got these as the results

2010-07-14 19:36:40.5738642

Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (Intel X86) Apr 2 2010 15:53:02 Copyright (c) Microsoft Corporation Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)

So as far as I can tell Sysutcdatetime still exists on SQL Server 2008 R2

Pieces
I checked using Sql server management studio on System Functions -> Date and Time Functions and it doesn't exist. I do not have access now to check again using the sql statement.
Marwan Aouida
+1  A: 

Thoughts:

  • What is the database compatibility level?
  • Are you 100% it's SQL Server 2008 R2 or SQL Server 2008?
gbn
not sure of the db compatibility level but I am pretty sure it is SQL server 2008 R2
Marwan Aouida
When you get a chance run @@VERSION and see
Pieces

related questions