首页 联系我 返回顶部
这几天偶尔出现评论丢失的现象
这在使用XmlDataProvider时未出现过
具体表现为:提交评论后提示发表成功,但数据库中没有数据。
查看代码:
try
        {
            Post.AddComment(comment);
           //其它代码
        }
        catch (Exception ex)
        {
            _Callback = ex.Message;
        }


Post.AddComment(comment);

public void AddComment(Comment comment)
		{
			CancelEventArgs e = new CancelEventArgs();
			OnAddingComment(comment, e);
			if (!e.Cancel)
			{
				Comments.Add(comment);

                BlogService.AddComment(comment);
               
				OnCommentAdded(comment);
				SendNotifications(comment);
			}
		}

BlogService最终会调用BlogProvider的InsertComment(Comment)方法,这里的BlogProvider是SqlDataProvider,继续跟进:
 public override void InsertComment(Comment comment)
        {
            List<SqlParameter> list = new List<SqlParameter>();
            string sql = "INSERT INTO be_PostComment (PostCommentID, PostID, CommentDate, Author, Email, Website, Comment, Country, Ip, IsApproved) " +
                                   "VALUES (@postcommentid, @id, @date, @author, @email, @website, @comment, @country, @ip, @isapproved)";

            list.Add(new SqlParameter("@postcommentid", comment.Id.ToString()));
            list.Add(new SqlParameter("@id", comment.Parent.Id.ToString()));
            list.Add(new SqlParameter("@date", DateTime.Now));
            list.Add(new SqlParameter("@author", comment.Author));
            list.Add(new SqlParameter("@email", comment.Email));

            list.Add(new SqlParameter("@website", comment.Website.ToString() ?? ""));

            list.Add(new SqlParameter("@comment", comment.Content));
            list.Add(new SqlParameter("@country", comment.Country ?? ""));
            list.Add(new SqlParameter("@ip", comment.IP));
            list.Add(new SqlParameter("@isapproved", comment.IsApproved));
            try
            {
                SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.Text, sql, list.ToArray());
            }
            catch (Exception ex)  
            {
                SqlLogs.Log(ex.Message, "Exception");
                throw ex;
            }
            Post p = Post.Load(comment.Parent.Id);
            p.Comments.Add(comment);
            p.Comments.Sort();
        }

如果是入库失败的话,日志表里是应该有记录的,而此时日志表是空的,说明很有可能根本就没有走到InsertComment方法 -_-
用了个笨招,直接将InsertComment写到CommentView.ascx.cs,明天再找原因。
在此给热心回复却无故丢失了评论的朋友说声抱歉。

2 Responses

收起评论
  1. benben 九月 9 2008 , 11:52 #1
    benben
    我换到Sqlite的时候也出现类似情况,把发送邮件取消后,就正常了。
  2. 幻想曲 九月 9 2008 , 12:51 #2
    幻想曲
    @benben:
    是么?这个我倒没有跟踪过

Write a comment:



(将显示你的Gravatar图标)  



[b][/b] - [i][/i] - [u][/u]- [quote][/quote]

:-/ ^_^ :d :o :kiss: :) :p :se: [yeah] :( :love: :han: :up: :cry: :zzz: o_o

暂时停止交换链接.

评论提交有问题?