The DI (Data Integration) Server exposes services and APIs for a developer to interact with the business objects and eventually the data store of SAP Business One. This article is about connecting to the DI Server, first using Single Sign On, which uses the instance of an already running SAP B1 Client, and the second method connecting to the D1 Server by passing all authentication values to the API.
Connecting Using Single Sign On
Connecting through single sign-on uses the running instance of SAP B1 client to get a connection to the SAP B1 DI server. What this means is that you do not need to re-authenticate yourself since the running client has already done the authentication. What it also means is that if you do not have a running SAP B1 client, you will get a runtime error since it cannot use something that is not there.
This is the technique used for connecting to the DI Server if you are creating an add-on that will reside inside the SAP B1's fat client since your program will always run inside the client (and therefore the client is ensured to exist).
Here is the example code:
public SAPbobsCOM.Company oCompany = null;
private int ConnectToSAPB1()
{
// *******************************************************************
// Use an SboGuiApi object to establish the connection
// with the application and return an initialized application object
// *******************************************************************
SAPbouiCOM.Application SBO_Application = null;
SAPbouiCOM.SboGuiApi SboGuiApi = new SAPbouiCOM.SboGuiApi();
string sConnectionString = System.Convert.ToString(Environment.GetCommandLineArgs().GetValue(1));
// connect to a running SBO Application
SboGuiApi.Connect(sConnectionString);
// get an initialized application object
SBO_Application = SboGuiApi.GetApplication(-1);
string sCookie = string.Empty;
string sConnectionContext = string.Empty;
//First initialize the Company object
oCompany = new SAPbobsCOM.Company();
//Acquire the connection context cookie from the DI API.
sCookie = oCompany.GetContextCookie();
//Retrieve the connection context string from the UI API using the
//acquired cookie.
sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie);
//before setting the SBO Login Context make sure the company is not
//connected
if (oCompany.Connected == true)
{
oCompany.Disconnect();
}
//Set the connection context information to the DI API.
return oCompany.SetSboLoginContext(sConnectionContext);
}
Connecting Directly to the DI Server
SAPbobsCOM.Company sc = new SAPbobsCOM.Company();
//Put your Database instance name here
sc.Server = "(local)";
//Important! Put the type of database here
sc.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005;
//Put the database name here
sc.CompanyDB = "SBODemoUS";
//SAP user ID and password
sc.UserName = "manager";
sc.Password = "manager";
//Langauge
sc.language = SAPbobsCOM.BoSuppLangs.ln_English;
//DB connection parameter. In this example, we are using trusted connection
sc.UseTrusted = true;
lRetCode = sc.Connect();
//Check if connection is successful
if (lRetCode == 0)
{
MessageBox.Show("Connection successful!");
}
else
{
MessageBox.Show("Connection failed!");
}
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5