我有一个SQL Server(server1)和Web服务服务器(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;
}
我们的webservice服务器(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服务器是否会回滚更改?
顺便提一下,我使用Dapper与我的数据库进行交互。Log4net常见日志记录。
感谢您的时间, Esen