提交事务后访问行集

时间:2013-06-28 14:21:18

标签: django sql-server-2008 python-2.7 django-mssql

我的django和msssql(存储过程)有问题:

com_error at /add_client/
(-2147352567, 'Ocurri\xf3 una excepci\xf3n.', (0, u'Microsoft SQL Server Native
Client 10.0', u'The object is in a zombie state. An object may enter a zombie 
state when either ITransaction::Commit or ITransaction::Abort is called, or when a
storage object was created and not yet released.', None, 0, -2147418113), None)

存储过程:

ALTER PROCEDURE [dbo].[InsertPerson](
@first_name nvarchar(80),
@last_name nvarchar(80),
@dni nvarchar(10),
@sex nvarchar(2),
@phone_number nvarchar(10),
@cellular_number nvarchar(9),
@email nvarchar(50),
@bank_account nvarchar(25),
@department nvarchar(50),
@province nvarchar(50),
@district nvarchar(50),
@address nvarchar(50),
@description nvarchar(128),
@is_active nvarchar(2),
@creation_time bigint)

AS

SET NOCOUNT ON

INSERT INTO persons (first_name, last_name, dni, sex, phone_number, cellular_number,
email, bank_account, department, province, district, address, description, is_active,
creation_time)
VALUES(@first_name, @last_name, @dni, @sex, @phone_number, @cellular_number, @email,
@bank_account, @department, @province, @district, @address, @description, @is_active,
@creation_time)

SELECT @@IDENTITY AS person_id

SET NOCOUNT OFF

此过程工作正常,但问题是在提交事务后获取行集(获取插入ID)。

我在Django的观点是:

from django.db import transaction
...
@transaction.commit_manually
def add_client(request):
...
...
...
description = request.POST.get('description', '')
is_active = request.POST.get('is_active', '')
cursor = connection.cursor()
cursor.callproc("InsertPerson", (first_name, last_name, dni, sex, phone_number, cellular_number, email, bank_account, department, province, district, address, description,
                                 is_active, creation_time))
connection.commit()
row = cursor.fetchone()
return HttpResponse(json.dumps({"mensaje": row.person_id}), content_type='application/json')

0 个答案:

没有答案