我有一个 sql server (server1) 和 webservice server (server2)。server2 具有以下代码。它从客户端获取结果请求并更新数据库。
try
{
AppLogger.DebugFormat("Entered into save result - [{0}]", result.ID);
int retry = 0;
while (++retry <= 5)
{
try
{
using (var oConnection = new SqlConnection("Connection string"))
{
oConnection.Open();
AppLogger.Debug("Saving data into db");
oConnection.Execute("storedproc1", new
{
param1 = Convert.ToInt32(result.value1),
param2 = Convert.ToInt32(result.value2),
param3 = result.value3=="Success",
param4 = result.vaue4
}, commandType: CommandType.StoredProcedure);
AppLogger.DebugFormat("Save done with [{0}] try", retry);
break;
}
}
catch (SqlException sx)
{
if (retry == 5)
{
AppLogger.Debug("sql exception occured");
throw;
}
else
{
AppLogger.ErrorFormat("Exception occurred [{0}] time(s), going to retry again after a minute", sx, retry);
System.Threading.Thread.Sleep(1000 * 60);
}
}
}
}
catch (Exception ex)
{
AppLogger.Error("Unable to save result", ex);
throw;
}
网络服务服务器(Server2)碰巧遇到蓝屏错误并死机。我们重新启动它并从应用程序中找到以下日志信息。
10:32:41.046 Entered into save result - 100023
10:32:41.062 Saving data into db
10:32:41.062 Save done with 0 try
10:32:45.233 Entered into save result - 100024
10:32:41.248 Saving data into db
10:32:41.248 Save done with 0 try
但是 sql server (server1) 没有这个更新。
下面是我的存储过程
Alter Procedure storedproc1
@Param1 int,
@Param2 int,
@Param4 varchar(2000),
@Param3 bit
AS
SET NOCOUNT ON
BEGIN
Declare @param5 varchar(30)
select @param5=col1 from table1 where col2=@param1 and col3=@param2
UPDATE table1 set col4=@param3, col5=@param4 where col2=@param1 and col3=@param2
IF not exists (select 1 from table1 where col1 = @param5 and col5 is null and col4 is null)
BEGIN
UPDATE table2 set col2='statuschange'
where col1 in (select distinct col6 from table1 where col1=@param5)
END
END
有人能告诉我为什么应用程序服务器说保存完成而 sql 服务器没有更新吗?
sql server 是否回滚连接丢失的更改?
顺便说一句,我使用 dapper 与我的数据库通信。Log4net 常用日志记录。
谢谢你的时间,埃森