我试图使用pyodbc(使用Python 2.7)调用存储过程将记录插入SQL Server 2012表.我正在通过一张临时桌子.
我抛弃了我的sql,当通过SQL Server管理控制台执行时,它生成了以下外键错误:
Msg 547, Level 16, State 0, Procedure spInsertBondTickerValues, Line 26
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__BondTickerValue__756D6ECB".
The conflict occurred in database "QuantDev", table "dbo.Tickers".
The statement has been terminated.
Run Code Online (Sandbox Code Playgroud)
但是,pyodbc没有提出异常.如何测试生成的游标或连接以了解发生了问题,以及如何获取错误消息?
非常感谢你.
编辑这是完整的SQL文本:
DECLARE @rawTbl [dbo].TickerValueTableType
INSERT INTO @rawTbl (Ticker, BBName, LastValue, ValueTime, SourceDescr) VALUES
('IBM', 'Equity', 179.230000, '2013-11-01 00:00:00.000000', 'Bloomberg'),
('SPX', 'Index', 1803.710000, '2013-12-10 00:00:00.000000', 'Bloomberg')
EXEC [dbo].spInsertBondTickerValues @rawTbl
Run Code Online (Sandbox Code Playgroud)
编辑2这是相关的Python代码:
def execSQLwithCommit(self, sql):
cursor …Run Code Online (Sandbox Code Playgroud)