Advertisement
Guest User

Connect code sap

a guest
Nov 29th, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1.  
  2. /// <summary>
  3. /// Initialises server settings, sets up connection credentials and attempts
  4. /// a new connection to SAP Business One server.
  5. /// </summary>
  6. /// <returns>Connection result as integer. Returns 0 if connection was successful</returns>
  7. public int Connect()
  8. {
  9. /*
  10. All the server settings and user credentials used below are stored in App.config file.
  11. ConfigurationManager is being used to read the App.config file.
  12. You can store you own settings in App.config or use actual values directly in the code:
  13. company.Server = "sapb1server";
  14. Example.App.config is included in this project, rename it to App.config and populate it with your own values.
  15. */
  16.  
  17. company.Server = ConfigurationManager.AppSettings["server"].ToString();
  18. company.CompanyDB = ConfigurationManager.AppSettings["companydb"].ToString();
  19.  
  20. string sqlVersion = ConfigurationManager.AppSettings["SQLVersion"].ToString();
  21. if (sqlVersion == "2014")
  22. {
  23. company.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014;
  24. }
  25. if (sqlVersion == "2016")
  26. {
  27. company.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016;
  28. }
  29.  
  30. company.DbUserName = ConfigurationManager.AppSettings["dbuser"].ToString();
  31. company.DbPassword = ConfigurationManager.AppSettings["dbpassword"].ToString();
  32. company.UserName = ConfigurationManager.AppSettings["user"].ToString();
  33. company.Password = ConfigurationManager.AppSettings["password"].ToString();
  34. company.language = SAPbobsCOM.BoSuppLangs.ln_English_Gb;
  35. company.UseTrusted = false;
  36. company.LicenseServer = ConfigurationManager.AppSettings["licenseServer"].ToString();
  37.  
  38. connectionResult = company.Connect();
  39.  
  40. if (connectionResult != 0)
  41. {
  42. company.GetLastError(out errorCode, out errorMessage);
  43. }
  44.  
  45. return connectionResult;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement