Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Initialises server settings, sets up connection credentials and attempts
- /// a new connection to SAP Business One server.
- /// </summary>
- /// <returns>Connection result as integer. Returns 0 if connection was successful</returns>
- public int Connect()
- {
- /*
- All the server settings and user credentials used below are stored in App.config file.
- ConfigurationManager is being used to read the App.config file.
- You can store you own settings in App.config or use actual values directly in the code:
- company.Server = "sapb1server";
- Example.App.config is included in this project, rename it to App.config and populate it with your own values.
- */
- company.Server = ConfigurationManager.AppSettings["server"].ToString();
- company.CompanyDB = ConfigurationManager.AppSettings["companydb"].ToString();
- string sqlVersion = ConfigurationManager.AppSettings["SQLVersion"].ToString();
- if (sqlVersion == "2014")
- {
- company.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014;
- }
- if (sqlVersion == "2016")
- {
- company.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016;
- }
- company.DbUserName = ConfigurationManager.AppSettings["dbuser"].ToString();
- company.DbPassword = ConfigurationManager.AppSettings["dbpassword"].ToString();
- company.UserName = ConfigurationManager.AppSettings["user"].ToString();
- company.Password = ConfigurationManager.AppSettings["password"].ToString();
- company.language = SAPbobsCOM.BoSuppLangs.ln_English_Gb;
- company.UseTrusted = false;
- company.LicenseServer = ConfigurationManager.AppSettings["licenseServer"].ToString();
- connectionResult = company.Connect();
- if (connectionResult != 0)
- {
- company.GetLastError(out errorCode, out errorMessage);
- }
- return connectionResult;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement