Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here




I am going to write a C# program to connect SAP.
Here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using SAPLogonCtrl;
using SAPBAPIControlLib;

namespace SapExplorer
    public partial class frmSapExplorer : Form
        SAPLogonControlClass sapLogon;
        SAPBAPIControlClass sapBapi;
        SAPLogonCtrl.Connection sapConnection;

        public frmSapExplorer()

            sapLogon = new SAPLogonControlClass();
            sapBapi = new SAPBAPIControlClass();

        private bool logonSAP()
            sapLogon.ApplicationServer = ConfigurationSettings.AppSettings["sapserver"];
            sapLogon.Client = ConfigurationSettings.AppSettings["sapclient"];
            sapLogon.System = ConfigurationSettings.AppSettings["sapsystem"];
            sapLogon.Language = ConfigurationSettings.AppSettings["saplang"];
            sapLogon.User = txtUsername.Text;
            sapLogon.Password = txtPassword.Text;

            sapConnection = (SAPLogonCtrl.Connection)sapLogon.NewConnection();

            return sapConnection.Logon(0, true);

        private void logoffSAP()

        private void btnLogon_Click(object sender, EventArgs e)
            if (logonSAP())
                MessageBox.Show("Logon OK");
                toolStripStatusLabel1.Text = "SAP is connected";                
                MessageBox.Show("Logon NG");
                toolStripStatusLabel1.Text = "SAP is disconnected";

        private void btnLogoff_Click(object sender, EventArgs e)
            MessageBox.Show("Logoff SAP");
            toolStripStatusLabel1.Text = "SAP is disconnected";

        private void btnCallBapi_Click(object sender, EventArgs e)
            sapBapi.Connection = sapConnection;
            Object bapiService = sapBapi.GetSAPObject("BapiService", "", "", "", "", "", "", "", "", "", "");



When I run sapBapi.Connection = sapConnection;
it prompted System.AccessViolationException.

What should I do?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close