Skip to Content
author's profile photo
Former Member

Reg Connection Error

Hi All,

I am conneting the DB theu the following code.. It is working fine for some databases,but same code will throw an error for some other databases..but previously it was working fine. but after some time it throws the following error

<u><b>" Attempted to read or write protected memory. This is often an indication that other memory is corrupt"</b></u>

<u>Code is below:</u>

Private Sub ConnectToCompany()

oCompany = New SAPbobsCOM.Company

oCompany.Server = Trim(txtservername.Text.ToString())

oCompany.CompanyDB = Trim(txtcmpdb.Text.ToString())

oCompany.UserName = txtcmpusrname.Text.ToString()

oCompany.Password = txtcmppassword.Text.ToString()

oCompany.language = SAPbobsCOM.BoSuppLangs.ln_English

oCompany.DbUserName = txtdbusrname.Text.ToString()

oCompany.DbPassword = txtdbpassword.Text.ToString()

Try

oCompany.Connect()

oCompany.GetLastError(lErrcode, sErrmsg)

If lErrcode <> 0 Then

MsgBox(sErrmsg)

Else

MsgBox("Connection Esstablished", MsgBoxStyle.Information)

End If

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

For eg:

i connected the SBODemo_India Database thru this code.. i created few tables and fields and i deleted the same and recreated tables for few times.. After some time the same Database thrown an above error

What can i do on this ?

Some body can help me on this to solve

Regards

Suresh

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 06:06 AM

    Dear Suresh,

    to connect DB , try single sigh on method.

    Single Sign-On Process---

    1.) The DI API Company object creates a cookie for the current DI API session. This cookie is available for the UI API using the GetContextCookie method.

    2.) The UI API Company object uses this cookie as an encryption key to encrypt the connection information—user code and password. The encrypted connection information is session dependent, and therefore cannot be reused for other sessions.

    Method: GetConnectionContext(Cookie).

    3.) The DI API Company object deciphers the encrypted connection information—based on the cookie created in step 1, and then sets the connection information (variable: conStr) for logging to the Company database.

    Method: SetSboLoginContext(conStr).

    4.) The DI API Company object connects to the company database.

    There is no need to set the AddonIdentifier property twice. Instead, you can set the identifier string before calling the Connect method of the UI API.

    The following code shows you how to utilize the Single Sign-On:

    Dim link As New SAPbouiCOM.SboGuiApi

    Dim pCmp As New SAPbobsCOM.Company

    Dim Cookie As String

    Dim conStr As String

    Dim ret As Long

    '// Connect the UI API to the running SAP Business One application

    link.Connect "***Put Connection String***"

    Set app = link.GetApplication

    '// Acquire the connection context cookie from the DI API

    Cookie = pCmp.GetContextCookie

    '// Retrieve the connection context string from the UI API using the 'acquired cookie

    conStr = app.Company.GetConnectionContext(Cookie)

    '// before setting the SBO Login Context make sure the company ' is not connected

    If pCmp.Connected = True Then

    pCmp.Disconnect

    End If

    '// Set the connection context information to the DI API

    ret = pCmp.SetSboLoginContext(conStr)

    if not ret = 0 then

    exit sub '// the operation has failed

    end if

    '// Establish the connection to the company database

    ret = pCmp.Connect()

    Add comment
    10|10000 characters needed characters exceeded