1

過去数日間 subsonic 3.0 を使用していて、問題が発生しました。ActiveRecord を使用し、既存のレコードで save を呼び出すと、次のことが発生しました。

[SqlException (0x80131904): The conversion of a char data type to a datetime
                            data type resulted in an out-of-range datetime value.
                            The statement has been terminated.]

私が使用しているコードは、問題を示すためのものです。

public void ButtonCreate_OnClick(object sender, EventArgs e) {
    stPost post = new stPost();
    post.postCreatedDate = DateTime.Now;
    post.postDescription = "cool post at " + DateTime.Now.ToString();
    post.postGuid = Guid.NewGuid();
    post.postTitle = "Post title";
    post.postUpdatedDate = DateTime.Now;

    post.Save();
}

public void ButtonUpdate_OnClick(object sender, EventArgs e) {
    stPost post = stPost.All().ToList<stPost>()[0];
    if (post != null && !post.IsNew()) {
        post.postDescription = "cool post UPDATED at " + DateTime.Now.ToString();
        post.postTitle = "Post title Updated";
        post.postUpdatedDate = DateTime.Now;

        post.Save();
    }
}

SQL プロファイラーと resharper を調べると、insert ステートメントと update ステートメントがまったく異なる方法で生成されることがわかりました。挿入時に、次のSQLコードを取得しています:

exec sp_executesql N'INSERT INTO 
 [dbo].[stPost]([dbo].[stPost].[postGuid],[dbo].[stPost].
 [postCreatedDate],[dbo].[stPost].[postUpdatedDate],[dbo].
 [stPost].[postTitle],[dbo].[stPost].[postDescription],[dbo].[stPost].[deleted])
VALUES
 (@ins_dbostPostpostGuid,@ins_dbostPostpostCreatedDate,
  @ins_dbostPostpostUpdatedDate,@ins_dbostPostpostTitle,
  @ins_dbostPostpostDescription,@ins_dbostPostdeleted);
SELECT SCOPE_IDENTITY() as new_id;
SELECT SCOPE_IDENTITY() as new_id',N'@ins_dbostPostpostGuid uniqueidentifier,
               @ins_dbostPostpostCreatedDate datetime,
               @ins_dbostPostpostUpdatedDate datetime,
               @ins_dbostPostpostTitle nvarchar(10),
               @ins_dbostPostpostDescription nvarchar(32),
               @ins_dbostPostdeleted bit',
               @ins_dbostPostpostGuid='91695935-588B-4617-8DB0-14210E97F718',
               @ins_dbostPostpostCreatedDate=''2009-07-14 14:11:52:997'',
               @ins_dbostPostpostUpdatedDate=''2009-07-14 14:11:52:997'',
               @ins_dbostPostpostTitle=N'Post title',
               @ins_dbostPostpostDescription=N'cool post at 14.07.2009 14:11:52',
               @ins_dbostPostdeleted=0

そしてアップデートで

exec sp_executesql N'UPDATE [stPost] 
 SET postDescription=@up_postDescription, 
postTitle=@up_postTitle, 
postUpdatedDate=@up_postUpdatedDate
 WHERE [dbo].[stPost].[postID] =
 @0',N'@up_postDescription varchar(40),
 @up_postTitle varchar(18),
 @up_postUpdatedDate varchar(19),
 @0 int',
 @up_postDescription='cool post UPDATED at 14.07.2009 14:11:58',
 @up_postTitle='Post title Updated',
 @up_postUpdatedDate='14.07.2009 14:11:58',
 @0=2

挿入日と更新日はさまざまな方法で渡されます。また、「14.07.2009」を解析すると範囲外の値になります。ローカル カルチャがロシア語に設定されており、SQL サーバーの照合順序が Cyrillic_General_CI_AS に設定されているため、カルチャ/グローバル化設定のどこかに問題がある可能性があると思います。ただし、問題は挿入時には発生せず、更新時にのみ発生します。そして、これは問題が亜音速のどこかにあると私に思わせます。どんな助けやアイデアも大歓迎です。

ウラジミール

4

0 に答える 0