dotnetspider.com Home page     All Communities

SAP Business One


Connection Between SAP and .Net



My Profile 
  • Sign In
  •  
  • Register

  • Links 
  • Message Center
  •  
  • File Manager
  •  
  • Members
  •  
  • Hall Of Fame
  •  
  • Site Configuration





  • Connection Between SAP and .Net


    Posted Date: 18 Jun 2009      Total Responses: 3

    Posted By: rengan       Member Level: Bronze     Points: 5


    Connection Between SAP and Dotnet

    Step1:-
    First add the Empty Project
    File->New Project->Empty Project

    Step 2:-
    Right click the Project Name->Choose Add Reference->Add Reference window will display
    ->Choose COM Tab-->Choose SAP Business One DI API version 2007 and SAP Business One UI

    API version 2007 A-->Then ok


    Step 3:
    Right click the Project Name->Add->Add NewItem->Module

    Step 4:
    Import the System.Reflection name space.
    Step 5:

    Create the objects for SAPbouiCOM and SAPbobsCOM


    add the below code in Module and run it

    Imports System.Reflection
    Module Module1
    Public WithEvents application As SAPbouiCOM.Application
    Public company As SAPbobsCOM.Company
    Public Function SetConnectionContext() As Integer
    Try
    Dim bnnStrCookie As String
    Dim bnnStrConnectionContext As String
    company = New SAPbobsCOM.Company
    bnnStrCookie = company.GetContextCookie
    bnnStrConnectionContext = application.Company.GetConnectionContext(bnnStrCookie)
    If company.Connected = True Then
    company.Disconnect()
    End If
    SetConnectionContext = company.SetSboLoginContext(bnnStrConnectionContext)

    Catch Ex As Exception
    application.MessageBox(Ex.Message)

    Finally

    End Try

    End Function
    Public Sub SetApplication()


    Dim bonGuiSboGuiApi As SAPbouiCOM.SboGuiApi
    Dim bnnStrConnectionString As String
    bonGuiSboGuiApi = New SAPbouiCOM.SboGuiApi

    Try
    bnnStrConnectionString = Environment.GetCommandLineArgs.GetValue(1)
    bonGuiSboGuiApi.Connect(bnnStrConnectionString)
    application = bonGuiSboGuiApi.GetApplication()

    Catch Ex As IndexOutOfRangeException
    bnnStrConnectionString =

    "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D00560049004

    90056"
    bonGuiSboGuiApi.Connect(bnnStrConnectionString)
    application = bonGuiSboGuiApi.GetApplication()

    Catch Ex As Exception
    application.MessageBox(Ex.Message)

    Finally

    End Try

    End Sub
    Private Sub Class_Init()
    SetApplication()
    If Not SetConnectionContext() = 0 Then
    application.MessageBox("Failed setting a connection to DI API")
    End
    End If
    If Not ConnectToCompany() = 0 Then
    application.MessageBox("Failed connecting to the company's Data Base")
    End
    End If
    application.StatusBar.SetText("Connected...", SAPbouiCOM.BoMessageTime.bmt_Short,

    SAPbouiCOM.BoStatusBarMessageType.smt_Success)
    End Sub
    Public Function ConnectToCompany() As Integer

    Try
    If company.Connected = True Then
    company.Disconnect()
    End If
    ConnectToCompany = company.Connect

    Catch Ex As Exception
    application.MessageBox(Ex.Message)

    Finally

    End Try

    End Function

    Sub Main()
    Try
    Class_Init()

    Catch Ex As Exception
    application.MessageBox(Ex.Message)

    Finally

    End Try

    End Sub

    End Module




    Responses

    Author: Nikhil Gaur    14 Aug 2009Member Level: BronzeRating: 2 out of 52 out of 5     Points: 2
    nice post rangan.
    can you please explain me more about SAP i am new in this field and want to know more about SAP as i heard much about it.


    Author: Programmer    26 Aug 2009Member Level: BronzeRating: 2 out of 52 out of 5     Points: 5
    You can also connect to company using the following function -

    Public Function ConnectToCompany()
    Dim objCompany As SAPbobsCOM.Company
    objCompany = New SAPbobsCOM.Company
    objCompany = application.Company.GetDICompany
    objCompany.Connect()
    If objCompany.Connected = False Then
    application.MessageBox("You are not connected to company !")
    End If
    End Function

    Call the above function after the function SetApplication().



    Post Reply
    You must Sign In to post a response.
    Previous : Hi Friends
    Return to Discussion Forum
    Post New Message
    Category: