/// <summary> /// Connect only DI Api /// </summary> /// <param name="serverName">SQL Server Name</param> /// <param name="serverType">Server type</param> /// <param name="companyDb"></param> /// <param name="dbUsername"></param> /// <param name="dbPassword"></param> /// <param name="username">SBO Username</param> /// <param name="password">SBO Password</param> /// <param name="licenceServer">Licence Server</param> public static void DiConnect(string serverName, SAPbobsCOM.BoDataServerTypes serverType, string companyDb, string dbUsername = null, string dbPassword = null, string username = null, string password = null, string licenceServer = null) { _diCompany = new SAPbobsCOM.Company { Server = serverName, DbServerType = serverType, CompanyDB = companyDb }; if (licenceServer != null) { _diCompany.LicenseServer = licenceServer; } if (string.IsNullOrEmpty(username)) { _diCompany.UseTrusted = true; } else { _diCompany.UseTrusted = false; _diCompany.UserName = username; _diCompany.Password = password; _diCompany.DbUserName = dbUsername; _diCompany.DbPassword = dbPassword; } var connectResponse = _diCompany.Connect(); if (connectResponse != 0) { int errCode; string errMsg; _diCompany.GetLastError(out errCode, out errMsg); Logger.Debug($"Servername={serverName}, CompanyDb={companyDb}, ServerType={serverType}, " + $"DbUsername={dbUsername}, DbPassword={dbPassword}, " + $"SboUsername={username}, SboPassword={password}, " + $"UseTrusted={_diCompany.UseTrusted}, " + $"LicenceServer={licenceServer}"); throw new Exception($"DI Connect Error: {errCode} {errMsg}"); } if (serverType == BoDataServerTypes.dst_HANADB) { HanaHandlers.Register(); } }
/// <summary> /// Connect UI and DI API /// </summary> /// <param name="connectionString">Connection String from SBO Main Application</param> /// <param name="loggingEnabled">Is SBO Common Logging enabled</param> public static void Connect(string connectionString = null, bool loggingEnabled = true) { //connectionString = DebugConnectionString; if (connectionString == null) { connectionString = Environment.GetCommandLineArgs().Length > 1 ? Convert.ToString(Environment.GetCommandLineArgs().GetValue(1)) : string.Empty; } var sboGuiApi = new SAPbouiCOM.SboGuiApi(); _diCompany = new SAPbobsCOM.Company(); try { sboGuiApi.Connect(connectionString); _application = sboGuiApi.GetApplication(); var contextCookie = _diCompany.GetContextCookie(); var diCompanyConnectionString = _application.Company.GetConnectionContext(contextCookie); var responseCode = _diCompany.SetSboLoginContext(diCompanyConnectionString); ErrorHelper.HandleErrorWithException(responseCode, "DI API Could not Set Sbo Login Context", _diCompany); var connectResponse = _diCompany.Connect(); ErrorHelper.HandleErrorWithException(connectResponse, $"DI API Could not connect.", _diCompany); if (loggingEnabled) { SboAppLogger.Enable(); } var assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; Logger.Info($"{assemblyName} connected"); SetAppEvents(); } catch (Exception ex) { Logger.Error($"SboApp UI Connect Error: {ex.Message}", ex); throw; } }
public Connection(string Servername, string Dbuser, string Dbpassword, string SAPDBName, string SAPUser, string SAPUserPassword, string SAPLicense) { int errCode = 0; string errMessage = ""; try { SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company(); oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2017; oCompany.Server = Servername; oCompany.DbUserName = Dbuser; oCompany.DbPassword = Dbpassword; oCompany.CompanyDB = SAPDBName; oCompany.UserName = SAPUser; oCompany.Password = SAPUserPassword; oCompany.LicenseServer = SAPLicense; int i = oCompany.Connect(); if (i == 0) { identity = identity + Servername + ";"; identity = identity + Dbuser + ";"; identity = identity + Dbpassword + ";"; identity = identity + SAPDBName + ";"; identity = identity + SAPUser + ";"; identity = identity + SAPUserPassword + ";"; identity = identity + SAPLicense + ";"; companyInstance = oCompany; } else { oCompany.GetLastError(out errCode, out errMessage); throw new Exception("Error Code : " + errCode.ToString() + " | " + "Error Desc : " + errMessage); } } catch (Exception ex) { throw ex; } }
public void copyDocuments(BoDocumentTypes docType) { try { SAPbobsCOM.Company comp = new SAPbobsCOM.Company(); comp.CompanyDB = "SBO_Digistar"; comp.DbServerType = BoDataServerTypes.dst_MSSQL2008; comp.Server = "B1DEV"; comp.UserName = "******"; comp.Password = "******"; comp.DbUserName = "******"; comp.DbPassword = "******"; comp.Connect(); Documents doc = (Documents)comp.GetBusinessObject(BoObjectTypes.oInvoices); } catch (Exception e) { } }
/// <summary> /// Realiza la conexión con SAP /// </summary> /// <param name="msgError">Mensaje de error de SAP</param> /// <returns>True / False</returns> public bool ConectarSAP(ref string msgError) { try { if (_oCompany == null) { _oCompany = new Company(); } DesconectarSAP(); if (!_oCompany.Connected) { _oCompany.Server = Extensor.Configuracion.CONEXION_SAP.ServerNameSAP; _oCompany.LicenseServer = Extensor.Configuracion.CONEXION_SAP.ServidorLicenciasSAP; _oCompany.DbServerType = BoDataServerTypes.dst_MSSQL2016; _oCompany.CompanyDB = Extensor.Configuracion.CONEXION_SAP.BaseSAP; _oCompany.UserName = Extensor.Configuracion.CONEXION_SAP.UserSAP; _oCompany.Password = Extensor.Configuracion.CONEXION_SAP.PassSAP; _oCompany.DbUserName = Extensor.Configuracion.CONEXION_SAP.UserSQL; _oCompany.DbPassword = Extensor.Configuracion.CONEXION_SAP.PassSQL; _oCompany.language = BoSuppLangs.ln_Spanish_La; int CodigoError = _oCompany.Connect(); if (CodigoError != 0) { string oDescription = null; _oCompany.GetLastError(out CodigoError, out oDescription); msgError = Convert.ToString(CodigoError) + " :: " + oDescription; return(false); } } return(true); } catch (Exception ex) { throw new Exception("Error al conectar con SAP : " + ex); } }
public static void ConnectViaDI(String dbServer, BoDataServerTypes dbServerType, String companyDb, String user, String password, String licenseServer, BoSuppLangs language = BoSuppLangs.ln_English) { try { // 1. Initiate the company instance for the first time if (oCompany == null) { oCompany = new SAPbobsCOM.Company(); } // 2. Set Company Property for login oCompany.Server = dbServer; oCompany.DbServerType = dbServerType; oCompany.CompanyDB = companyDb; oCompany.UserName = user; oCompany.Password = password; oCompany.LicenseServer = licenseServer; oCompany.language = language; oCompany.UseTrusted = false; IRetCode = oCompany.Connect(); // 4. Error Handling if (IRetCode != 0) { MsgBoxWrapper(oCompany.GetLastErrorDescription()); } // 5. (Optional) XML Export Configuration oCompany.XmlExportType = BoXmlExportTypes.xet_ExportImportMode; } catch (Exception ex) { MsgBoxWrapper(ex.Message + " " + ex.StackTrace); } }
public static bool ConnectToSAP() { Console.WriteLine("Connecting to SAP."); bool ret = true; try { int lRetCode; oCompany = new SAPbobsCOM.Company(); Properties.Settings setting = new Properties.Settings(); oCompany.Server = setting.LicenseServer; oCompany.CompanyDB = setting.CompanyDB; oCompany.CompanyDB = setting.CompanyDB; oCompany.DbServerType = BoDataServerTypes.dst_MSSQL2008; //db user name oCompany.DbUserName = setting.DBUserName; oCompany.DbPassword = setting.DBPassword; //user name oCompany.UserName = setting.SAPUserName; //user password oCompany.Password = setting.SAPPassword; oCompany.language = SAPbobsCOM.BoSuppLangs.ln_English; //Use Windows authentication for database server. // True for NT server authentication, //False for database server authentication. oCompany.UseTrusted = false; //insert license server and port oCompany.LicenseServer = setting.LicenseServer.Trim() + ":30000"; //Connecting to a company DB lRetCode = oCompany.Connect(); if (lRetCode != 0) { oCompany.GetLastError(out errCode, out errMsg); Console.WriteLine(errMsg); oCompany.Disconnect(); ret = false; } } catch (Exception ex) { Console.WriteLine(ex.Message); } if (ret) { Console.WriteLine("Connection to SAP ok."); } //Return True return(ret); }
private int ConnectToCompany() { return(oCompany.Connect()); }
private void ConnectSBO(ref SAPbobsCOM.Company oCompany, ref int nErr, ref string sErr, string CompanyName) { VisualD.Core.TVisualDCore Core; sErr = ""; nErr = 0; oLog.LogMsg("ConnectSBO start", "F", "D"); SBO_VID_Currency.Properties.Settings.Default.Reload(); // Set company properties switch (SBO_VID_Currency.Properties.Settings.Default.SQLType) // 0->2005 1-2008 2-2012 { case 0: oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005; break; case 1: oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008; break; case 2: oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012; break; case 3: oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014; break; case 4: oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016; break; case 5: oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2017; break; case 6: oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2019; break; case 7: oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB; break; } oCompany.UseTrusted = false; oCompany.Server = SBO_VID_Currency.Properties.Settings.Default.SBOServer; // +":40000"; oCompany.DbUserName = SBO_VID_Currency.Properties.Settings.Default.DBUserName; oCompany.DbPassword = Crypt.Decrypt(SBO_VID_Currency.Properties.Settings.Default.DBPassword, "VIDCurrency0-09"); oCompany.CompanyDB = CompanyName; oCompany.UserName = globals.SBOUser; oCompany.Password = globals.SBOPass; //Try to connect nErr = oCompany.Connect(); oLog.LogMsg("try connect", "F", "D"); if (nErr != 0) // if the connection failed { oCompany.GetLastError(out nErr, out sErr); } else { SAPbobsCOM.Recordset oRecordSet; // A recordset object oRecordSet = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); if (oCompany.DbServerType == SAPbobsCOM.BoDataServerTypes.dst_HANADB) { oRecordSet.DoQuery("select \"InstallNo\" from \"CINF\""); } else { oRecordSet.DoQuery("select InstallNo from cinf"); } oLog.LogMsg("Select InstallNo", "F", "D"); if (oRecordSet.EoF) { sErr = "Installation Number no encontrado"; nErr = -1; return; } string InstallId = (System.String)oRecordSet.Fields.Item("installNo").Value; if (oCompany.DbServerType == SAPbobsCOM.BoDataServerTypes.dst_HANADB) { oRecordSet.DoQuery("Select CURRENT_DATE \"Fec\" from DUMMY"); } else { oRecordSet.DoQuery("Select GetDate() Fec"); } DateTime Fec = (System.DateTime)(oRecordSet.Fields.Item("Fec").Value); TGlobalAddOnOptions FOpcionAddOn = new TGlobalAddOnOptions(); List <String> FAddonsList = new List <String>(); string oK = "C9A80FB4-D8C3-11E0-AEAD-7E944824019B"; oLog.LogMsg("Before accept", "F", "D"); Core = new VisualD.Core.TVisualDCore(InstallId, Fec, ref FOpcionAddOn, ref oK, FAddonsList); if (Core.ExitApp) { sErr = "Licencia " + Core.Error; nErr = -2; oCompany.Disconnect(); } else if (oK != "E6DCA176-D8C3-11E0-93B0-86944824019B") { sErr = "VisualDCore enlace 2 inválido."; nErr = -3; oCompany.Disconnect(); } else { sErr = "OK"; } if (Core.EsDEmo) { oLog.LogMsg("Licencia de demostracion " + Core.AddOnName, "F", "W"); } oLog.LogMsg("after accept", "F", "D"); } oLog.LogMsg("Conexion a SBO: " + CompanyName + " - " + sErr, "F", "I"); }
public SAP() { SQLiteCommand sqlite_cmd; SQLiteDataReader sqlite_datareader; String key = "trugLk"; //buscando dados de conexao no banco SQLite try { String path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); myconn = new SQLiteConnection("DataSource=" + path + "\\LiberB1\\LiberB1DB.db;"); myconn.Open(); //MyLogger.Log("Conectado ao RabbitMQ"); } catch (Exception ex) { MyLogger.Log("Error 509 - " + ex.Message); MessageBox.Show("Error 509 - " + ex.Message); return; } sqlite_cmd = myconn.CreateCommand(); sqlite_cmd.CommandText = "SELECT [servername],[dbname],[sapuser],[sappass],[sqltype],[dbId],[dbPass]" + "from[Connection]; "; sqlite_datareader = sqlite_cmd.ExecuteReader(); sqlite_datareader.Read(); //usando os dados de conexao para conectar no SAP int retCode = -1; string strMsg; try { oCompany = new SAPbobsCOM.Company(); oCompany.Server = sqlite_datareader.GetString(0); oCompany.CompanyDB = sqlite_datareader.GetString(1); switch (sqlite_datareader.GetString(4)) { case "dst_MSSQL": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL; break; case "dst_DB_2": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_DB_2; break; case "dst_SYBASE": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_SYBASE; break; case "dst_MSSQL2005": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005; break; case "dst_MAXDB": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MAXDB; break; case "dst_MSSQL2008": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008; break; case "dst_MSSQL2012": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012; break; case "dst_MSSQL2014": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014; break; case "dst_HANADB": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB; break; case "dst_MSSQL2016": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016; break; case "dst_MSSQL2017": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2017; break; default: oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2017;; break; } oCompany.UserName = sqlite_datareader.GetString(2); oCompany.Password = Cryptography.Decrypt(sqlite_datareader.GetString(3), key); oCompany.UseTrusted = false; oCompany.DbUserName = sqlite_datareader.GetString(5); oCompany.DbPassword = Cryptography.Decrypt(sqlite_datareader.GetString(6), key); myconn.Close(); retCode = oCompany.Connect(); if (retCode != 0) { strMsg = oCompany.GetLastErrorDescription(); MyLogger.Log("Não Conectado, verifique as configurações de conexão"); this.connect = false; } else { MyLogger.Log("SAP Conectado!"); this.connect = true; } } catch (Exception ex) { MyLogger.Log("Error 504 - " + ex.Message); MessageBox.Show("Error 504 - " + ex.Message); } }
private void button2_Click(object sender, EventArgs e) { labelConnLiber.Text = String.Empty; labelConnSAP.Refresh(); labelConnSAP.Text = "Conectando..."; labelConnSAP.ForeColor = Color.Gray; labelConnSAP.Refresh(); SAPbobsCOM.Company oCompany = null; int retCode = -1; string strMsg; try { oCompany = new SAPbobsCOM.Company(); oCompany.Server = textBoxServerName.Text; //oCompany.LicenseServer = textBoxServerName.Text; oCompany.CompanyDB = textBoxDBName.Text; oCompany.language = SAPbobsCOM.BoSuppLangs.ln_English; oCompany.UseTrusted = false; switch (comboBox1.Text) { case "dst_MSSQL": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL; break; case "dst_DB_2": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_DB_2; break; case "dst_SYBASE": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_SYBASE; break; case "dst_MSSQL2005": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005; break; case "dst_MAXDB": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MAXDB; break; case "dst_MSSQL2008": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008; break; case "dst_MSSQL2012": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012; break; case "dst_MSSQL2014": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014; break; case "dst_HANADB": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB; break; case "dst_MSSQL2016": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016; break; case "dst_MSSQL2017": oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2017; break; default: oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2017;; break; } //oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016; //dst_MSSQL;//1 //dst_DB_2;//2 //dst_SYBASE;//3 //dst_MSSQL2005;//4 //dst_MAXDB;//5 //dst_MSSQL2008;//6 //dst_MSSQL2012;//7 //dst_MSSQL2014;//8 //dst_HANADB;//9 //dst_MSSQL2016;//10 ////dst_MSSQL2017;//11 //oCompany.SLDServer = "172.16.0.4"; //oCompany.LicenseServer = "SAP-SERVER"; oCompany.DbUserName = textBoxDBID.Text; oCompany.DbPassword = textBoxDBPass.Text; oCompany.UserName = textBoxSAPUser.Text; oCompany.Password = textBoxSAPPass.Text; oCompany.UseTrusted = false; retCode = oCompany.Connect(); if (retCode != 0) { strMsg = oCompany.GetLastErrorDescription(); labelConnSAP.Text = strMsg; labelConnSAP.ForeColor = Color.Red; MessageBox.Show(strMsg); } else { labelConnSAP.Text = "Conectando a " + oCompany.CompanyName; labelConnSAP.ForeColor = Color.Green; button1.BackColor = Color.Green; oCompany.Disconnect(); } } catch (Exception ex) { MessageBox.Show(ex.Message); labelConnSAP.Text = ex.Message; labelConnSAP.ForeColor = Color.Red; } }
public static int ConnectToCompany(Company customCompany) { Translator = new TranslatorTool(); Company = customCompany; return Company.Connect(); }