【发布时间】:2011-02-20 22:01:45
【问题描述】:
我正在尝试从一个名为suspend 的数据库插入到ANimals 数据库中名为Notification 的表中。我的存储过程是这样的:
ALTER PROCEDURE [dbo].[spCreateNotification]
-- Add the parameters for the stored procedure here
@notRecID int,
@notName nvarchar(50),
@notRecStatus nvarchar(1),
@notAdded smalldatetime,
@notByWho int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO Animals.dbo.Notification
(
NotRecID,
NotName,
NotRecStatus,
NotAdded,
NotByWho
)
values (@notRecID, @notName, @notRecStatus, @notAdded, @notByWho);
END
空插入是为了补充一列否则不会被填充,我尝试了不同的方法,比如在表名之后使用列的名称,然后只在值中指示我已经填写的字段得到。我知道这不是存储过程的问题,因为我是从 sql server management studio 执行的,它可以引入参数。那么我猜想问题一定出在我调用存储过程的时候:
public void createNotification(Notification not)
{
try
{
DB.spCreateNotification(not.NotRecID, not.NotName, not.NotRecStatus,
(DateTime)not.NotAdded, (int)not.NotByWho);
}
catch
{
return;
}
}
我在这里调用方法:
public void createNotifications(IList<TemporalNotification> notifications)
{
foreach (var TNot in notifications)
{
var ts = RepositoryService._suspension.getTemporalSuspensionForNotificationID(TNot.TNotRecID);
Notification notification = new Notification();
if (ts.Count != 0)
{
notification.NotName = TNot.TNotName;
notification.NotRecID = TNot.TNotRecID;
notification.NotRecStatus = TNot.TNotRecStatus;
notification.NotAdded = TNot.TNotAdded;
notification.NotByWho = TNot.TNotByWho;
if (TNot.TNotToReplace != 0)
{
var suspensions = RepositoryService._suspension.getSuspensionsAttached((int)TNot.TNotToReplace);
foreach (var sus in suspensions)
{
sus.CtsEndDate = TNot.TNotAdded;
sus.CtsEndNotRecID = TNot.TNotRecID;
DB.spModifySuspensionWhenNotificationIsReplaced((int)TNot.TNotToReplace, (int)sus.CtsEndNotRecID, (DateTime) sus.CtsEndDate);
}
DB.spReplaceNotification((int)TNot.TNotToReplace, DateTime.Now);
createNotification(notification);
}
else
{
createNotification(notification);
}
}
}
deleteTemporalNotifications(notifications);
}
它不记录数据库中的值。我一直在调试并对此感到生气,因为它在我手动执行时有效,但在我自动化应用程序中的过程时无效。有人看到我的代码有什么问题吗?
谢谢
编辑:添加了更多代码。它仍然无法改变这一点,我的意思是,如果我执行它,程序就可以工作,所以我不知道可能是什么错误。事实上,我没有得到任何错误。可能是写入不在存储过程的数据库中的表中的问题吗?
【问题讨论】:
-
当你单步执行代码时,它真的到达调用过程的地步了吗?
-
是的,它会穿过它,好像什么都没有。调用后我检查表,数据库中没有任何反应。我不知道还能尝试什么,从来没有这么卡住过哈哈
-
您是否更改了程序以枚举 INSERT 子句中的列?
-
您是否尝试过在 .NET 代码调用过程时运行 SQL Profiler 以查看它传递给存储过程的确切内容?
-
@Thomas - 是的,我改变了它,我没有编辑但我改变了 sql 查询
标签: asp.net sql asp.net-mvc stored-procedures