I am unable to rollback using the following code snippet and need help:
import clr
import sys
clr.AddReference('System.Data')
from System.Data.SqlClient import SqlConnection, SqlParameter, SqlTransaction
conn_string = "****"
connection = SqlConnection(conn_string)
connection.Open()
createuser = connection.CreateCommand()
createuser.CommandText = "****"
try:
reader = createuser.ExecuteReader()
reader.Close()
except:
reader.Rollback()
Thanks!
I understand now, however now I'm having a problem where its expecting a string but I cant do the parametrized values if I put the SQL query string in as the argument:
createuser.CommandText = "****"
createuser.Parameters.AddWithValue("@Username", username);
usertransaction = connection.BeginTransaction(createuser)
try:
usertransaction.Commit()
except:
usertransaction.Rollback()