Skip to Content
author's profile photo Former Member
Former Member

Company.connect error

The following code snippet is being used to connect to the company:

Dim connectstr As String

Dim oCompany As SAPbobsCOM.Company

Dim lngConnect As Long

oCompany = New SAPbobsCOM.Company

oCompany.Server = SBO_Appln.Company.ServerName

oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL

oCompany.CompanyDB = SBO_Appln.Company.DatabaseName

oCompany.UserName = SBO_Appln.Company.UserName

connectstr = SBO_Appln.Company.GetConnectionContext(oCompany.GetContextCookie)


lngConnect = oCompany.Connect

Catch ex As Exception


End Try

The statement "oCompany.connect" is generating the exception "Object Reference not set to an instance of an object" though a new instance of oCompany is created.

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Oct 19, 2005 at 01:40 PM

    Hmmm a strange way to do a single signon. Look at the single signon sample or follow this code:

    //UI Conncetion
    SboGuiApi SboGui = new SboGuiApiClass(); 
    Application _SboApplication; 
    string conStr = Environment.GetCommandLineArgs()[1];
    _SboApplication = SboGui.GetApplication(-1);
    //DI (Single signon)
    SAPbobsCOM.Company _SboCompany = new SAPbobsCOM.CompanyClass(); 
    string cookie = SboCompany.GetContextCookie();
    string conStr = _SboApplication.Company.GetConnectionContext(cookie);
    if(!SboCompany.Connected) {
      if(SboCompany.Connect() != 0) {
      else {
        //Connection OK

    If its not a Single signon conncetion you are after use the followeing function

    private static SAPbobsCOM.Company _SboCompany = new SAPbobsCOM.CompanyClass(); 
    /// <summary>
    /// Create a DI Connection
    /// </summary>
    /// <param name="Server">Name of the server</param>
    /// <param name="Username">The SBO Username</param>
    /// <param name="Password">The SBO Password</param>
    /// <param name="DatabaseName">The Databasename</param>
    /// <param name="DbUsername">The Username for the MSSQL (Not used if UseTrusted = true)</param>
    /// <param name="DbPassword">The Password for the MSSQL (Not used if UseTrusted = true)</param>
    /// <param name="LicenseServer">Name of the license server</param>
    /// <param name="UseTrusted">If connection should use a trusted connection to Connect to MSSQL</param>
    /// <param name="Language">The connection language</param>
    public static void Connect(string Server, string Username, string Password, string DatabaseName, string DbUsername, string DbPassword, string LicenseServer,bool UseTrusted, BoSuppLangs Language) {
      SboCompany.Server = Server;
      SboCompany.UserName = Username;
      SboCompany.Password = Password;
      SboCompany.CompanyDB = DatabaseName;
      SboCompany.DbUserName = DbUsername;
      SboCompany.DbPassword = DbPassword;
      SboCompany.LicenseServer = LicenseServer;
      SboCompany.UseTrusted = UseTrusted;
      if(!SboCompany.Connected) {
        if(SboCompany.Connect() != 0) {

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2005 at 01:35 PM

    Hi Rashmi,

    You should pass your connection string after the connect method like

    lngConnect = oCompany.Connect(connectstr)

    Hope it helps,


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 19, 2005 at 01:42 PM

    MY single logon connect part is

    Dim sContextCookie As String

    Dim sConnContext As String


    oCmp = New SAPbobsCOM.Company

    sContextCookie = oCmp.GetContextCookie

    sConnContext = oApp.Company.GetConnectionContext(sContextCookie)



    Return True

    Catch ex As System.Exception

    MsgBox(ex.Message + vbCrLf + ex.StackTrace, MsgBoxStyle.Critical, "SBO BAPI ERROR")

    Return False

    End Try

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.