开发者

Sysutcdatetime in Sql Server 2008 R2, is it deprecated?

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 currentUtcDat开发者_JAVA技巧e = 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 ?


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


  • Not in SQL Server 2005
  • In SQL Server 2008
  • In SQL Server 2008 R2

Thoughts:

  • What is the database compatibility level?
  • Are you 100% it's SQL Server 2008 R2 or SQL Server 2008?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜