存储过程不会触发一段时间
Stored procedure don't fire some time
我有一个存储过程SetMonthlyGroup
(代码如下所示),但是有点大但不复杂它只是在每个月重复每个@Accounts
集@Amount
对所有 @monthCount
重复
顺便说一句,我测试了它并且它有效。
ALTER PROCEDURE [yeganeh].[SetMonthlyGroup]
@Accounts text,
@StartDate datetime,
@monthCount int,
@SanNum int,
@Amount bigint
AS
BEGIN
DECLARE @returnList AS TABLE (Name nvarchar(500),
IDSource int,
id int NOT NULL PRIMARY KEY IDENTITY(1,1)
)
DECLARE @result int
SET @result = (SELECT COUNT(*)
FROM dbo.splitstring(@Accounts,','))
INSERT INTO @returnList
SELECT *
FROM dbo.splitstring(@Accounts,',')
SET @result = (SELECT COUNT(*) FROM @returnList)
DECLARE @i int
SET @i = 0
DECLARE @AccountIndex nvarchar(20)
DECLARE @monthIndex int
SET @monthIndex = 0
DECLARE @payDate datetime
SET @payDate = getdate()
begin try
begin transaction
while @i < @resualt
begin
set @i = @i + 1
select @AccountIndex = Name
from @returnList
where id = @i
set @monthIndex = 0
while @monthIndex < @monthCount
begin
set @payDate = (DATEADD(month, @monthIndex, @StartDate))
insert into Sandogh_Monthly
values (@SanNum, @AccountIndex, @Amount, 'NotPaid', @payDate)
set @monthIndex = @monthIndex + 1
end
end
insert into Logs
values (@SanNum, 'Monthly', 'System Log', getdate(), 'Transacction Commit', NULL)
commit
end try
begin catch
rollback
insert into Logs
values (@SanNum, 'Monthly', 'System Log', getdate(), 'Transacction rollback', NULL)
end catch
END
我把这个存储过程作为一个事务来执行,并将日志保存在日志中table
有时我使用 ADO.net 和 ExecuteNonQuery
returns true 执行存储过程,但没有行显示在日志中 table,每月也没有行 table.
我这样称呼它:
public bool inserttMonthly(string accounts, int month, DateTime startDate)
{
DB dbsql = new DB();
dbsql.AddParams("@Accounts", accounts);
dbsql.AddParams("@StartDate", startDate);
dbsql.AddParams("@monthCount", month);
dbsql.AddParams("@SanNum", this.Mont_SanNum);
dbsql.AddParams("@Amount", this.Mont_Amount);
return dbsql.ExecuteWithNoResultDSParamsSP("SetMonthlyGroup");
}
和分贝class
public bool ExecuteWithNoResultDSParamsSP(string storedProcedureName)
{
this.Connect();
try
{
this.cmd.CommandText = storedProcedureName;
this.cmd.CommandType = CommandType.StoredProcedure;
this.cmd.Connection = this.cn;
this.cmd.BeginExecuteNonQuery();
this.cn.Close();
return true;
}
catch (Exception ex)
{
return false;
}
}
我像下面的代码一样更改了 db class,它 returns :-
值 ID = 1,状态 = RanToCompletion,方法 =“{null}”,结果 =“”System.IAsyncResult{System.Threading.Tasks.Task}
System.IAsyncResult value= this.cmd.BeginExecuteNonQuery();
string msg = value.ToString();
最后我决定在 Ajax 之前完成。使用存储过程的新方式
function setMonth(account ) {
// $("#Loading").show();
setTimeout(function () {
$.ajax({
url: "../UCSandogh/Ajax/Month.aspx",
type: "get",
dataType: "HTML",
async: false,
cache: false,
timeout: 30000,
data: { action: "setMonth", account: account, date: sDate, amount: moneyAmount, monthCount: monthCountInput },
error: function () {
return false;
},
success: function (msg) {
progressBar(parseInt(currentProg));
if (msg) {
lastInsertStatus = true;
return true;
} else {
lastInsertStatus = false;
return false;
}
}
}).done(NextAcc())
}, 3000);
}
最后我决定在 Ajax 之前完成。使用存储过程的新方式
function setMonth(account ) {
// $("#Loading").show();
setTimeout(function () {
$.ajax({
url: "../UCSandogh/Ajax/Month.aspx",
type: "get",
dataType: "HTML",
async: false,
cache: false,
timeout: 30000,
data: { action: "setMonth", account: account, date: sDate, amount: moneyAmount, monthCount: monthCountInput },
error: function () {
return false;
},
success: function (msg) {
progressBar(parseInt(currentProg));
if (msg) {
lastInsertStatus = true;
return true;
} else {
lastInsertStatus = false;
return false;
}
}
}).done(NextAcc())
}, 3000);
}
我有一个存储过程SetMonthlyGroup
(代码如下所示),但是有点大但不复杂它只是在每个月重复每个@Accounts
集@Amount
对所有 @monthCount
顺便说一句,我测试了它并且它有效。
ALTER PROCEDURE [yeganeh].[SetMonthlyGroup]
@Accounts text,
@StartDate datetime,
@monthCount int,
@SanNum int,
@Amount bigint
AS
BEGIN
DECLARE @returnList AS TABLE (Name nvarchar(500),
IDSource int,
id int NOT NULL PRIMARY KEY IDENTITY(1,1)
)
DECLARE @result int
SET @result = (SELECT COUNT(*)
FROM dbo.splitstring(@Accounts,','))
INSERT INTO @returnList
SELECT *
FROM dbo.splitstring(@Accounts,',')
SET @result = (SELECT COUNT(*) FROM @returnList)
DECLARE @i int
SET @i = 0
DECLARE @AccountIndex nvarchar(20)
DECLARE @monthIndex int
SET @monthIndex = 0
DECLARE @payDate datetime
SET @payDate = getdate()
begin try
begin transaction
while @i < @resualt
begin
set @i = @i + 1
select @AccountIndex = Name
from @returnList
where id = @i
set @monthIndex = 0
while @monthIndex < @monthCount
begin
set @payDate = (DATEADD(month, @monthIndex, @StartDate))
insert into Sandogh_Monthly
values (@SanNum, @AccountIndex, @Amount, 'NotPaid', @payDate)
set @monthIndex = @monthIndex + 1
end
end
insert into Logs
values (@SanNum, 'Monthly', 'System Log', getdate(), 'Transacction Commit', NULL)
commit
end try
begin catch
rollback
insert into Logs
values (@SanNum, 'Monthly', 'System Log', getdate(), 'Transacction rollback', NULL)
end catch
END
我把这个存储过程作为一个事务来执行,并将日志保存在日志中table
有时我使用 ADO.net 和 ExecuteNonQuery
returns true 执行存储过程,但没有行显示在日志中 table,每月也没有行 table.
我这样称呼它:
public bool inserttMonthly(string accounts, int month, DateTime startDate)
{
DB dbsql = new DB();
dbsql.AddParams("@Accounts", accounts);
dbsql.AddParams("@StartDate", startDate);
dbsql.AddParams("@monthCount", month);
dbsql.AddParams("@SanNum", this.Mont_SanNum);
dbsql.AddParams("@Amount", this.Mont_Amount);
return dbsql.ExecuteWithNoResultDSParamsSP("SetMonthlyGroup");
}
和分贝class
public bool ExecuteWithNoResultDSParamsSP(string storedProcedureName)
{
this.Connect();
try
{
this.cmd.CommandText = storedProcedureName;
this.cmd.CommandType = CommandType.StoredProcedure;
this.cmd.Connection = this.cn;
this.cmd.BeginExecuteNonQuery();
this.cn.Close();
return true;
}
catch (Exception ex)
{
return false;
}
}
我像下面的代码一样更改了 db class,它 returns :-
值 ID = 1,状态 = RanToCompletion,方法 =“{null}”,结果 =“”System.IAsyncResult{System.Threading.Tasks.Task}
System.IAsyncResult value= this.cmd.BeginExecuteNonQuery();
string msg = value.ToString();
最后我决定在 Ajax 之前完成。使用存储过程的新方式
function setMonth(account ) {
// $("#Loading").show();
setTimeout(function () {
$.ajax({
url: "../UCSandogh/Ajax/Month.aspx",
type: "get",
dataType: "HTML",
async: false,
cache: false,
timeout: 30000,
data: { action: "setMonth", account: account, date: sDate, amount: moneyAmount, monthCount: monthCountInput },
error: function () {
return false;
},
success: function (msg) {
progressBar(parseInt(currentProg));
if (msg) {
lastInsertStatus = true;
return true;
} else {
lastInsertStatus = false;
return false;
}
}
}).done(NextAcc())
}, 3000);
}
最后我决定在 Ajax 之前完成。使用存储过程的新方式
function setMonth(account ) {
// $("#Loading").show();
setTimeout(function () {
$.ajax({
url: "../UCSandogh/Ajax/Month.aspx",
type: "get",
dataType: "HTML",
async: false,
cache: false,
timeout: 30000,
data: { action: "setMonth", account: account, date: sDate, amount: moneyAmount, monthCount: monthCountInput },
error: function () {
return false;
},
success: function (msg) {
progressBar(parseInt(currentProg));
if (msg) {
lastInsertStatus = true;
return true;
} else {
lastInsertStatus = false;
return false;
}
}
}).done(NextAcc())
}, 3000);
}