Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Transactions in VB.net

Posted on 2004-04-15
6
Medium Priority
?
6,200 Views
Last Modified: 2013-12-25
Hello,

I am trying to use transactions in my VB.net program. I have opened a connection, and have opened a transaction on it and

Dim m_objConn As OleDb.OleDbConnection
Dim m_objTrans As OleDb.OleDbTransaction
Dim m_objDA As OleDb.OleDbDataAdapter

m_objTrans = m_objConn.BeginTransaction()

I have a function like this :

Public Function ExecuteCommand(ByVal strQuery As String) As DataSet

        '*** Create a new Data Adapter by passing the query and the connection
        '*** object to it. Fill the dataset against that Dataadapter and
        '*** return the dataset back to the calling function.
        Dim objDS As New DataSet()
        Dim objDA As New OleDb.OleDbDataAdapter(strQuery, m_objConn)


        objDA.Fill(objDS)

        Return objDS
End Function

I am not using any command object in the code.

1. Is that ok? Can i populate my DAtaSet without using the command object?
2. When I execute the program, an InvalidOperationException is thrown with the following additional info:

Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The transaction property of the command has not been initialized.

Now The question is, when I am not using the command object, why am I getting this error?


Thanks.
0
Comment
Question by:manjirit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 39

Expert Comment

by:appari
ID: 10838633

when you are not using any data update sqls like Insert/Update/Delete why to start a transaction?

Remove m_objTrans = m_objConn.BeginTransaction()
0
 
LVL 7

Expert Comment

by:ramesh12
ID: 10839373
When you use Adapter,  internally the adapter object uses the Command objects

C here

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlDataAdapterClassTopic.asp?frame=true
0
 

Author Comment

by:manjirit
ID: 10869696
Hi Ramesh,

Thanks for ur reply. THe thing is I am using the data update sqls, which I pass into strQuery string. I need to have the beginTransaction on connection. The thing is the adapter may be using the command object internally. But since I am not using one explicitely, how can I enlist a transaction to it? I am using only strQuery string and no command object.
0
 
LVL 41

Accepted Solution

by:
graye earned 200 total points
ID: 10921594
The use of the Oledb "flavor" of the ADO.Net suite is suspicous...  What database back-end are you using?  File-based databases (like Microsoft Access) aren't gonna support ADO.Net transactions.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question