开发者

I Can't create an ado.net transaction in IronPython

I'm trying to create an ado.net transaction in IronPython in asp.net and I'm getting the following error "couldn't find member Rollback"

I tried to see what's different in my ironpython ado.net transaction with a vb.net ado.net transaction but I can't see the differences or find the reason why one doesnt work and the other does. Perhaps I'm just not seeing something, these are the test codes

VB.NET

Partial Class prueba
    Inherits sql_conexiones

    Sub bt_aceptar_click(ByVal s As Object, ByVal e As EventArgs)
        Dim objTransaction As SqlTransaction
        Dim conpubs As SqlConnection = New SqlConnection("Persist Security Info=False;Data Source=PABLODALMA;Initial Catalog=SistemaHYM;User ID=sa;Password=usuario;Connect Timeout=180")
        Dim strUpdateA As String = "UPDATE bancos SET descripcion_banco = 'prueba' WHERE cod_banco = 1"
        Dim strUpdateB As String = "UPDATE bancos SET descripcion_banco = 'pruebados' WHERE cod_banco = 1"
        Dim cmdUpdateA As SqlCommand
        Dim cmdUpdateB As SqlCommand
        cmdUpdateA = New SqlCommand(strUpdateA, conpubs)
        cmdUpdateB = New SqlCommand(strUpdateB, conpubs)
        conpubs.Open()
        objTransaction = conpubs.BeginTransaction
        Try
            cmdUpdateA.ExecuteNonQuery()
            cmdUpdateB.ExecuteNonQuery()
            objTransaction.Commit()
            Response.Write("ok")
        Catch ex As Exception
            objTransaction.Rollback()
            Response.Write("no ok")
        Finally
            conpubs.Close()
        End Try
    End Sub
End Class

IronPython

import clr
clr.AddReference('System.Data')             # Agrega espacio de nombres Data
from System.Data import *                   #uso esta forma para importar o la otra?
clr.AddReference('System')                  
import System                               # Agrega espacio de nombres System       

def bt_aceptar_click(sender,e):
    objTransaction = System.Data.SqlClient.SqlTransaction
    conpubs = System.Data.SqlClient.SqlConnection("Persist Security Info=False;Data Source=PABLODALMA;Initial Catalog=SistemaHYM;User ID=sa;Password=usuario;Connect Timeout=180")
    strUpdateA = "UPDATE bancos SET descripcion_banco = 'prueba' WHERE cod_banco = 1"
    strUpdateB = "UPDATE bancos SET descripcion_banco = 'pruebados' WHERE cod_banco = 1"
    cmdUpdateA = System.Data.SqlClient.SqlCommand(strUpdateA, conpubs)
    cmdUpdateB = System.Data.SqlClient.SqlCommand(strUpdateB, conpubs)
    conpubs.Open()
    objTransaction = conpubs.BeginTransaction
    try:
        cmdUpdateA.ExecuteNonQuery()
        cmdUpdateB.ExecuteNonQuery()
        objTransaction.Commit()
        Response.Write("ok")
    except:
        objTransaction.Rollback()
        Response.Write("no ok")
    else:
        conpubs.Close()

Something else to say it's the object inspector is showing very different objects. When VB.NET says

objTransaction System.Data.SqlClient.SqlTransaction

  • Connection System.Data.SqlClient.SqlConnection
  • IsolationLevel ReadCommitted(4096)

IronPython says objTransaction Microsoft.Scripting.BoundBuiltinFunction with a wider set of subitems. This probably means something related to the problem but I dont have the technical level to know it. There are some开发者_StackOverflow references to the object being related to an ado.net transaction, such as "public member" --> instance --> "System.Data.SqlClient.SqlTransaction". Is IronPython creating the object I need or it's just creating another type of object and that's why I'm getting the error?


I think you may have a minor syntax error. Try adding brackets after BeginTransaction, as follows:

objTransaction = conpubs.BeginTransaction()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜