PDA

Click to See Complete Forum and Search --> : MTS Mystery


abhijit
Jun 4th, 2001, 09:30 AM
Hi Everyone,
i would like you to solve this mts mystery for me.

this is my function as copied from MSDN Code Center.

Public Function DoStuffBad() As Variant
On Error GoTo ErrHandler
Dim oConn As New ADODB.Connection
Dim oCmd As New ADODB.Command
Dim oRS As ADODB.Recordset
Dim sTemp As String
Dim cNString As String
cNString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb;Persist Security Info=True"
oConn.Open cNString
Set oCmd.ActiveConnection = oConn
oCmd.CommandText = "SELECT * FROM Authors"
oCmd.CommandType = adCmdText
Set oRS = oCmd.Execute

Do While Not oRS.EOF
sTemp = sTemp & ";" & oRS.Fields(1)
oRS.MoveNext
Loop

'This FAILS if executed within an MTS transaction with ADO 'Unspecified Error' message:
oConn.Execute "INSERT INTO Authors (Author, [Year Born]) values ('Dr Dolittle',1925)"
GetObjectContext.SetComplete

DoStuffBad = "Worked ok" & " " & sTemp

Exit Function
ErrHandler:
GetObjectContext.SetAbort
Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
DoStuffBad = Err.Description
End Function

My project has the necessary references added. However the function does not work.

Could anyone care to highlight why?

Regards,
Abhijit

crispin
Jun 5th, 2001, 11:30 AM
Dim oConn As New ADODB.Connection
Dim oCmd As New ADODB.Command


this is your first problem, you must not DIM AS NEW within an MTS transaction, your objects will not get created within context, there are considerations within MTS, I can't detail them here it would take me too long, might help you to read about it on MSDN...

hope this helps...

abhijit
Jun 13th, 2001, 10:45 AM
i have got the answer now.
cheers!