Transaction

  • Thread starter Thread starter simonZ
  • Start date Start date
S

simonZ

SqlCommand oCmd;
SqlTransaction tran;

oCmd = new SqlCommand("myStoredProcedure",myFunctions.createConnection());
oCmd.CommandType = CommandType.StoredProcedure;

tran=oCmd.Transaction.Connection.BeginTransaction();//I get an error: null exception

Any idea?
Without tran everything works.

regards,Simon
 
Try something like this:

SqlConnection cnn;
SqlCommand oCmd;
SqlTransaction tran;

cnn = myFunctions.createConnection();
tran = cnn.BeginTransaction();

oCmd = new SqlCommand("myStoredProcedure", cnn);
oCmd.CommandType = CommandType.StoredProcedure;
oCmd.Transaction = tran;

In your code oCmd.Transaction is still null when you try to access the
Connection property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top