Results 1 to 3 of 3

Thread: MTS Mystery

  1. #1

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Question MTS Mystery

    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

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Code:
    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...
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228
    i have got the answer now.
    cheers!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width