The client runs my code on error. They sent me SQL from profilder.
When I paste it into SQL Server Management Studio, it fails: Error converting varchar data type to datetime
However, this will not work when I run it in my local dev block or another server.
To test, I created a simple application with an L2S data file containing a single object that looks something like this:
public class UserAccount
{
public int Id { get; set; }
public string Username { get; set; }
public DateTime? LastActivity { get; set; }
}
Insert a record and then update it:
var account = db.UserAccounts.Single(a => a.Username == "Mojo");
account.LastActivity = DateTime.Now;
db.SubmitChanges();
Records are updated in the database. But when I get T-SQL from Profiler:
exec sp_executesql N'UPDATE [UserAccount] SET [LastActivity] = @p2 WHERE ([Id] = @p0) AND ([Username] = @p1) AND ([LastActivity] IS NULL)',N'@p0 int,@p1 nvarchar(4),@p2 datetime',@p0=1,@p1=N'Mojo',@p2='2009-11-10 14:04:41.7470000'
and execute it in SQL Server Management Studio, I get: Error converting varchar data type to datetime
What am I missing?