0

I am connecting to SAP via COM, using ActiveX controls dragged into the Form. In VB6 I write:

Private Sub Form_Terminate()
    SAPBAPIControl.Connection.Logoff
End Sub

Private Sub SAPLogonControl_Click()
    Set SAPBAPIControl.Connection = SAPLogonControl.NewConnection
    SAPBAPIControl.Connection.Client = "100"
    If SAPBAPIControl.Connection.Logon(0, False) Then
        MsgBox SAPBAPIControl.Connection.IsConnected
    End If
End Sub

In VB.NET 2010 I write:

Public Class MainForm
    Private Sub MainForm_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    AxSAPBAPIControl1.Connection.Logoff()
End Sub

    Private Sub AxSAPLogonControl1_ClickEvent(sender As Object, e As System.EventArgs) Handles     AxSAPLogonControl1.ClickEvent
        AxSAPBAPIControl1.Connection = AxSAPLogonControl1.NewConnection()
        AxSAPBAPIControl1.Connection.Client = "100"
        If AxSAPBAPIControl1.Connection.Logon(0, False) Then
            MsgBox(AxSAPBAPIControl1.Connection.IsConnected)
        End If
    End Sub
End Class

and end up with:

Eine Ausnahme (erste Chance) des Typs "System.AccessViolationException" ist in mscorlib.dll aufgetreten. in .Client = "100"

VB6 just works.

Does anyone have an idea how to transfer the Connection Object to the other class in VB.NET?

Thanks for the help.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Johannes Maria Frank
  • 2,747
  • 1
  • 29
  • 38
  • 1
    Getting help with COM servers crashing with an access violation requires support from the vendor. – Hans Passant Oct 12 '12 at 00:00
  • Thank you for your suggestion. But the Vendors to contact would be: Microsoft and SAP. What would be a rought guess about my chances to get them to address the problem? So probably I am better off in closing the connection and reopen it every time I need a different feature. I just would have liked to avoid this. – Johannes Maria Frank Oct 15 '12 at 11:47
  • German "Eine Ausnahme..." translates into `An exception (first chance) of type "System.AccessViolationException" occurred in mscorlib.dll. in .client = "100"` – Sandra Rossi Apr 27 '23 at 17:37

1 Answers1

-1

At a guess: You are using Set in old VB6 code, i think that affects objects, linke in VBA. You might try something like

AxSAPBAPIControl1 =  AxSAPBAPIControl1.Connection = AxSAPLogonControl1.NewConnection()

I think AxSAPBAPIControl1 gives you a connection object and does not modify itself - so you are opening a new connection, which is never used, and then then the "unconnected" AxSAPBAPIControl1 is used. I dont know SAP-Com, but this kind of krad is happening in msoffice.interop happening sometimes. Please give me some feedback.

Christian Sauer
  • 10,351
  • 10
  • 53
  • 85