예제 #1
0
        /// <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(string connection)
        {
            /*
             * 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[connection + "companydb"].ToString();
            company.DbServerType  = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
            company.DbUserName    = ConfigurationManager.AppSettings["dbuser"].ToString();
            company.DbPassword    = ConfigurationManager.AppSettings["dbpassword"].ToString();
            company.UserName      = ConfigurationManager.AppSettings[connection + "user"].ToString();
            company.Password      = ConfigurationManager.AppSettings[connection + "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);
        }
예제 #2
0
    public static void ConnectViaSSO()
    {
        try
        {
            // 1. Connect to UI
            ConnectViaUI();

            oCompany = new SAPbobsCOM.Company();
            string sCookie = oCompany.GetContextCookie();

            string connInfo = oApp.Company.GetConnectionContext(sCookie);

            // It will set Server, db, username, password to the DI Company
            oCompany.SetSboLoginContext(connInfo);

            lRetCode = oCompany.Connect();
            MsgBoxWrapper("Addon MIS_TO_PROD Connected via SSO");

            CompDB = oCompany.CompanyDB;
        }
        catch (Exception ex)
        {
            MsgBoxWrapper(ex.Message);
        }
    }
예제 #3
0
        private static void swProConectarSap()
        {
            try
            {
                objConexionSap = new SAPbobsCOM.Company()
                {
                    Server        = varServidorSap,
                    DbServerType  = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014,
                    LicenseServer = varServidorLicencia,
                    CompanyDB     = varBaseDatosSap,
                    UserName      = varUsuarioSap,
                    Password      = varContraseñaSap,

                    DbUserName = varUsuarioBD,
                    DbPassword = varContraseñaBD,
                    UseTrusted = false
                };
                iError = objConexionSap.Connect();
                if (iError != 0)
                {
                    objConexionSap.GetLastError(out iError, out varMensaje);
                    throw new Exception(varMensaje);
                }
            }
            catch (Exception) { throw; }
        }
예제 #4
0
        static public int ConnectSqlSap(string serverName, string societe, string DbUserName, string DbPassword, string typeserver, string sapUserName, string sapPassword, string LicenseServer)
        {
            int connectionResult = 1;

            //string typeserver

            try
            {
                //sql
                oCompany.Server       = serverName;
                oCompany.CompanyDB    = societe;
                oCompany.DbUserName   = DbUserName;
                oCompany.DbPassword   = DbPassword;
                oCompany.DbServerType = SBOTools.Str2ServerType(typeserver);
                //sap
                oCompany.UserName      = sapUserName;
                oCompany.Password      = sapPassword;
                oCompany.LicenseServer = LicenseServer;
                //oCompany.language = SAPbobsCOM.BoSuppLangs.ln_French;
                oCompany.UseTrusted = false;
                //oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
                // Console.WriteLine("__"+oCompany.Connect());
                connectionResult = oCompany.Connect();
            }
            catch (Exception)
            {
                return(connectionResult);
            }

            return(connectionResult);
        }
예제 #5
0
        private bool Connect_usuario()
        {
            SAPbobsCOM.Company Company = new SAPbobsCOM.Company();
            Company.Server          = "hana:30015";
            Company.LicenseServer   = "sapb1:40000";
            Company.UseTrusted      = false;
            Company.DbServerType    = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
            Company.DbUserName      = "******";
            Company.DbPassword      = "******";
            Company.CompanyDB       = this.Empresa;
            Company.UserName        = this.Usuario;
            Company.Password        = this.Clave;
            Company.language        = SAPbobsCOM.BoSuppLangs.ln_Spanish_La;
            Company.AddonIdentifier = string.Empty;

            if (Company.Connect() != 0)
            {
                this.EstadoConexion = Company.GetLastErrorDescription();
                Company             = null;
                this.Conectado      = false;
            }
            else
            {
                Company.XMLAsString   = true;
                Company.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode;
                this.Empresa_SAP      = Company;
                this.Conectado        = true;
            }

            return(this.Conectado);
        }
예제 #6
0
 static void Main(string[] args)
 {
     Console.WriteLine("Hello");
     try {
         SAPbobsCOM.Company company = new SAPbobsCOM.Company();
         company.CompanyDB     = "SBODemoUS";
         company.Server        = "MIKISURFACE";
         company.LicenseServer = "MIKISURFACE:30000";
         company.SLDServer     = "MIKISURFACE:40000";
         company.DbUserName    = "******";
         company.DbPassword    = "******";
         company.UseTrusted    = true;
         company.UserName      = "******";
         company.Password      = "******";
         company.DbServerType  = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016;
         int    status    = company.Connect();
         string errorMsg  = company.GetLastErrorDescription();
         int    errorCode = company.GetLastErrorCode();
         System.Diagnostics.Debug.WriteLine($"Connection Status {status} msg {errorMsg} code {errorCode}");
         SAPbobsCOM.RecordsetEx rs = company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordsetEx);
         rs.DoQuery("select * from OITM");
         rs.MoveNext();
         string ic = rs.GetColumnValue("ItemCode");
         System.Diagnostics.Debug.WriteLine($"Item Code is {ic}");
         company.Disconnect();
         System.Diagnostics.Debug.WriteLine("Disconnected");
     } catch (Exception e) {
         System.Diagnostics.Debug.WriteLine(e.Message);
     }
 }
예제 #7
0
        private int ConnectToCompany()
        {
            int ConnectToCompanyReturn = 0;

            ConnectToCompanyReturn = oCompany.Connect();
            return(ConnectToCompanyReturn);
        }
예제 #8
0
 /// <summary>
 /// Builds a connection to SAP B1 via DI
 /// </summary>
 /// <returns></returns>
 public void Connect(ConnectionParams connectionParams)
 {
     this.connectionParams = connectionParams;
     if (this._company == null)
     {
         this._company = new SAPbobsCOM.Company();
     }
     if (!this._company.Connected)
     {
         _company.CompanyDB     = connectionParams.CompanyDB;
         _company.Server        = connectionParams.Server;
         _company.LicenseServer = connectionParams.LicenseServer;
         _company.SLDServer     = connectionParams.SLDServer;
         _company.DbUserName    = connectionParams.DbUserName;
         _company.DbPassword    = connectionParams.DbPassword;
         //UseTrusted must be false when DB User is defined, otherwise cannot connect to SBO-COMMON error is thrown on IIS
         _company.UseTrusted   = string.IsNullOrEmpty(connectionParams.DbUserName) ? connectionParams.UseTrusted : false;
         _company.UserName     = connectionParams.UserName;
         _company.Password     = connectionParams.Password;
         _company.DbServerType = connectionParams.boDataServerType();
         int status = _company.Connect();
         _company.XMLAsString = true;                 //THIS IS TERRIBLY IMPORTANT for XML handling
         System.Diagnostics.Debug.WriteLine("SAP DI is connected");
     }
     if (!this._company.Connected)
     {
         string errorMsg  = _company.GetLastErrorDescription();
         int    errorCode = _company.GetLastErrorCode();
         throw new Exception($"Connection was rejected msg { errorMsg } code { errorCode}");
     }
 }
        public static void InitializeCompany()
        {
            oCompany              = new SAPbobsCOM.Company();
            oCompany.Server       = ConfigurationManager.AppSettings["Server"];
            oCompany.language     = SAPbobsCOM.BoSuppLangs.ln_English;
            oCompany.UseTrusted   = false;
            oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
            oCompany.CompanyDB    = ConfigurationManager.AppSettings["CompanyDB"];
            oCompany.UserName     = ConfigurationManager.AppSettings["UserName"];
            oCompany.Password     = ConfigurationManager.AppSettings["UserPass"];
            oCompany.DbUserName   = ConfigurationManager.AppSettings["DbUserName"];
            oCompany.DbPassword   = ConfigurationManager.AppSettings["DbPassword"];

            if (oCompany.Connected == true)
            {
                oCompany.Disconnect();
            }

            long lRetCode = oCompany.Connect();

            if (lRetCode != 0)
            {
                int    temp_int    = 0;
                string temp_string = "";
                oCompany.GetLastError(out temp_int, out temp_string);

                Log.WriteLog("InitializeCompany Error: " + temp_string);
            }
        }
        public int Connect()
        {
            //pass the stored settings from app.config to a local variable
            company.Server     = ConfigurationManager.AppSettings["server"].ToString();
            company.CompanyDB  = ConfigurationManager.AppSettings["companydb"].ToString();
            company.DbUserName = ConfigurationManager.AppSettings["dbuser"].ToString();
            company.DbUserName = ConfigurationManager.AppSettings["dbpass"].ToString();
            //change this variable to your enviromen( sql 2012 - 2016)
            company.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
            company.UserName     = ConfigurationManager.AppSettings["user"].ToString();
            company.Password     = ConfigurationManager.AppSettings["password"].ToString();
            //choose the languge of your sap install (this must match!)
            company.language = SAPbobsCOM.BoSuppLangs.ln_Dutch;
            //true = if ssl is enable and not self signed !
            company.UseTrusted    = false;
            company.LicenseServer = ConfigurationManager.AppSettings["licenseserver"].ToString();

            connectionResult = company.Connect();
            if (connectionResult != 0)
            {
                //connection has failed !
                company.GetLastError(out errorCode, out errorMessage);
            }
            return(connectionResult);
        }
예제 #11
0
        public override async Task Execute(Message message, TelegramBotClient client)
        {
            var chatId = message.Chat.Id;

            SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
            int connect = int.MinValue;

            oCompany.Server     = "";
            oCompany.CompanyDB  = "";
            oCompany.DbUserName = "";
            oCompany.DbPassword = "";
            oCompany.UserName   = "";
            await client.SendTextMessageAsync(chatId, "Введіть логін:");

            oCompany.UserName = message.Text;
            if (oCompany.UserName != null)
            {
                oCompany.Password = "";
                //   await client.DeleteMessageAsync(chatId, message.MessageId);
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2017;

                connect = oCompany.Connect();
                string error = "error(0)";
                if (connect != 0)
                {
                    error = oCompany.GetLastErrorDescription();
                    await client.SendTextMessageAsync(chatId, error);
                }
                else
                {
                    await client.SendTextMessageAsync(chatId, "З'єднання з SAP успішне");
                }
            }
        }
예제 #12
0
        /// <summary>
        /// 连接B1账套
        /// </summary>
        /// <author>WangPeng</author>
        private static SAPbobsCOM.Company ConnectB1Company()
        {
            if (_SAPCompany == null)
            {
                _SAPCompany = new SAPbobsCOM.Company();
            }
            if (_SAPCompany.Connected == true)
            {
                return(_SAPCompany);
            }
            Logger.Writer("开始连接B1账套……");
            _SAPCompany.DbServerType  = (SAPbobsCOM.BoDataServerTypes)System.Enum.Parse(typeof(SAPbobsCOM.BoDataServerTypes), ConfigurationManager.AppSettings["SAPDBServerType"]);
            _SAPCompany.Server        = ConfigurationManager.AppSettings["DataSource"];
            _SAPCompany.language      = SAPbobsCOM.BoSuppLangs.ln_Chinese;
            _SAPCompany.UseTrusted    = Convert.ToBoolean(ConfigurationManager.AppSettings["UseTrusted"]);
            _SAPCompany.DbUserName    = ConfigurationManager.AppSettings["UserID"];
            _SAPCompany.DbPassword    = ConfigurationManager.AppSettings["Password"];
            _SAPCompany.CompanyDB     = ConfigurationManager.AppSettings["SAPInitialCatalog"];
            _SAPCompany.UserName      = ConfigurationManager.AppSettings["SAPUser"];
            _SAPCompany.Password      = ConfigurationManager.AppSettings["SAPPassword"];
            _SAPCompany.LicenseServer = ConfigurationManager.AppSettings["SAPLicenseServer"];
            int RntCode = _SAPCompany.Connect();

            if (RntCode != 0)
            {
                Logger.Writer(SAP.SAPCompany.GetLastErrorDescription());
                string message = SAP.SAPCompany.GetLastErrorDescription();
                throw new Exception(string.Format("ErrorCode:[{0}],ErrrMsg:[{1}];", SAP.SAPCompany.GetLastErrorCode(), SAP.SAPCompany.GetLastErrorDescription()));
            }
            Logger.Writer("已连接 " + _SAPCompany.CompanyName);
            return(_SAPCompany);
        }
예제 #13
0
        /// <summary>
        /// Connect SAP using DI API and replace string connection default.
        /// </summary>
        /// <param name="sapCredential"></param>
        public static void Connect(k.sap.SAPCredential sapCredential)
        {
            if (IsConnected())
            {
                conn.Disconnect();
            }

            conn = new SAPbobsCOM.Company();
            conn.DbServerType = (SAPbobsCOM.BoDataServerTypes)sapCredential.SapBoDataServerTypes;
            conn.Server       = sapCredential.DbServer;
            conn.language     = (SAPbobsCOM.BoSuppLangs)sapCredential.SapBoSuppLangs;
            conn.CompanyDB    = sapCredential.SapCompanyDb;
            conn.DbUserName   = sapCredential.SapDbUserName;
            conn.DbPassword   = sapCredential.SapDbPassword;
            conn.UserName     = sapCredential.SapUserName;
            conn.Password     = sapCredential.SapUserPassword;
            var res = conn.Connect();

            if (res != 0)
            {
                var error = conn.GetLastErrorDescription();
                var track = k.Diagnostic.TrackMessages(sapCredential.Info1());
                k.Diagnostic.Error(LOG, track, $"({res}) {error}.");
                throw new Exception($"Error to connect SAP using DI api. Error code {res}", new Exception(error));
            }
            else
            {
                k.Diagnostic.Debug(LOG, null, "SAP DI connected on {0} customer as {1}", conn.CompanyName, conn.UserName);
                LinkClient();
            }
        }
예제 #14
0
        public SAPbobsCOM.Company Connect(string pServer, string pDBName, string pDBUser, string pDBPassword, SAPbobsCOM.BoDataServerTypes pServerType,
                                          string pSAPUser, string pSAPPassword, ref int iErr)
        {
            if (pDBName == "")
            {
                iErr = 1;
            }

            if (iErr != 0)
            {
                return(null);
            }

            //oConnTrg = SQLDirect.oConnectToSql(txbDBServerTrg.Text, cmbSAPDBTrg.Text.Substring(0, cmbSAPDBTrg.Text.IndexOf(" - ")), txbDBUserTrg.Text, txbDBPassTrg.Text, true, bErr);
            oComp.Server = pServer;
            if (pServer == "")
            {
                oComp.Server = scServer;
            }

            oComp.DbUserName = pDBUser;
            if (pDBUser == "")
            {
                oComp.DbUserName = scSQLName;
            }

            oComp.DbPassword = pDBPassword;
            if (pDBPassword == "")
            {
                oComp.DbPassword = scSQLPass;
            }

            oComp.DbServerType = pServerType;
            //if (pServerType == null) oComp.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008;

            oComp.CompanyDB = pDBName;

            oComp.UserName = pSAPUser;
            if (pSAPUser == "")
            {
                oComp.UserName = scSAPName;
            }

            oComp.Password = pSAPPassword;
            if (pSAPPassword == "")
            {
                oComp.Password = scSAPPass;
            }

            iErr = oComp.Connect();
            if (iErr == 0)
            {
                return(oComp);
            }
            else
            {
                DImsg.MessageERR(iErr, oComp.GetLastErrorDescription());
                return(null);
            }
        }
예제 #15
0
        private void TestConnection()
        {
            SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
            ///Open the connection to sbo

            oCompany.Server        = ServerName;
            oCompany.LicenseServer = LicenseServer;
            oCompany.UserName      = UserName;
            oCompany.Password      = Password;
            oCompany.CompanyDB     = CompanyDB;
            oCompany.UseTrusted    = UseTrusted;
            if (!UseTrusted)
            {
                oCompany.DbUserName = DBUser;
                oCompany.DbPassword = DBPassword;
            }
            oCompany.DbServerType = dbServerType;


            int err = oCompany.Connect();

            if (err != 0)
            {
                sMessage = "Failed Connecting to SAP\n\r" + oCompany.GetLastErrorDescription();
            }
            else
            {
                sMessage = "Test connection successful";
                oCompany.Disconnect();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oCompany);
            GC.Collect();
        }
        public string ConectarBD()
        {
            oCompany              = new SAPbobsCOM.Company();
            oCompany.Server       = ConfigurationManager.AppSettings["Server"];
            oCompany.CompanyDB    = ConfigurationManager.AppSettings["Company"];
            oCompany.UserName     = ConfigurationManager.AppSettings["UserName"];
            oCompany.Password     = ConfigurationManager.AppSettings["Password"];
            oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
            oCompany.DbUserName   = ConfigurationManager.AppSettings["DbUserName"];
            oCompany.DbPassword   = ConfigurationManager.AppSettings["DbPassword"];

            if (oCompany.Connected == true)
            {
                oCompany.Disconnect();
            }

            retVal = oCompany.Connect();
            if (retVal != 0)
            {
                string retStr = oCompany.GetLastErrorDescription();
                return("Error " + retVal + " " + retStr);
            }
            else
            {
                //return "Conectado a " + oCompany.CompanyName;
                return(InsertarRegistroInspeccion());
            }
        }
예제 #17
0
        //Inicializa aplicacion
        public static void SetApplication()
        {
            //Se obtiene string de conexion de Cliente SAP B1
            if (Environment.GetCommandLineArgs().Count() == 1)
            {
                throw new Exception("No se agregaron los parametros de conexión...", new Exception("No se encontro string de conexión SAP B1"));
            }
            ConnectionString = Environment.GetCommandLineArgs().GetValue(1).ToString();

            //Se realiza conexion
            SAPbouiCOM.SboGuiApi client = new SAPbouiCOM.SboGuiApi();
            client.Connect(ConnectionString);
            SBOApplication = client.GetApplication(-1);

            //Se carga <<Company>> de aplicacion
            SBOCompany = new SAPbobsCOM.Company();
            string cookies           = SBOCompany.GetContextCookie();
            string connectionContext = SBOApplication.Company.GetConnectionContext(SBOCompany.GetContextCookie());

            SBOCompany.SetSboLoginContext(connectionContext);

            //Conexion con sociedad
            if (SBOCompany.Connect() != 0)
            {
                throw new Exception(SBOError);
            }
        }
예제 #18
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                oCompany              = new SAPbobsCOM.Company();
                oCompany.Server       = "192.168.1.233:30015";
                oCompany.SLDServer    = "192.168.1.233:40000";
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
                oCompany.CompanyDB    = "SBODEMOES";
                oCompany.UserName     = "******";
                oCompany.Password     = "******";
                oCompany.DbUserName   = "******";
                oCompany.DbPassword   = "******";

                int ret = oCompany.Connect();
                if (ret == 0)
                {
                    MessageBox.Show("Connection ok");
                }
                else
                {
                    MessageBox.Show("Connection failed: " + oCompany.GetLastErrorCode().ToString() + " - " + oCompany.GetLastErrorDescription());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection error: " + ex.Message);
            }
        }
예제 #19
0
 public static SAPbobsCOM.Company getOCompany(ref String sResultMsg)
 {
     SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
     if (!oCompany.Connected)
     {
         //// Set connection properties
         string TipoBD = Constantes.Servidor.TipoBD;
         oCompany.DbServerType  = GetDbServerType(TipoBD);
         oCompany.Server        = GetServer(TipoBD);
         oCompany.LicenseServer = GetLicenseServer(TipoBD);          // change to your company server
         oCompany.language      = SAPbobsCOM.BoSuppLangs.ln_Spanish; // change to your language
         oCompany.UseTrusted    = false;
         oCompany.DbUserName    = Constantes.Servidor.UsuarioServ;
         oCompany.DbPassword    = Constantes.Servidor.ContraServ;
         oCompany.CompanyDB     = Constantes.Compania.BaseCia;
         oCompany.UserName      = Constantes.Compania.UsuarioCia;
         oCompany.Password      = Constantes.Compania.Contrasena;
         //Try to connect
         if (oCompany.FailOperation(oCompany.Connect(), out sResultMsg))
         {
             return(oCompany);
         }
     }
     if (oCompany.Connected) // if connected
     {
         sResultMsg = String.Format("Se conecto a {0} | {1} | {2} "
                                    , oCompany.CompanyDB
                                    , oCompany.CompanyName
                                    , oCompany.Version);
     }
     return(oCompany);
 }
예제 #20
0
        private void connect()
        {
            try
            {
                objCompany              = new SAPbobsCOM.Company();
                objCompany.Server       = DataBaseServer;
                objCompany.UseTrusted   = false;
                objCompany.DbUserName   = DataBaseUserName;
                objCompany.DbPassword   = DataBasePassword;
                objCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
                objCompany.CompanyDB    = DataBaseName;
                objCompany.UserName     = CompanyUserName;
                objCompany.Password     = CompanyPassword;

                intRetCode = objCompany.Connect();

                if (intRetCode != 0)
                {
                    strMessage = objCompany.GetLastErrorDescription();
                }
                else
                {
                    strMessage = "Connected to " + objCompany.CompanyName;
                }
                MessageBox.Show(strMessage);
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }
        }
예제 #21
0
        private void connectToB1(ConfigurationInformation b1ConnectionInfo)
        {
            SAPbobsCOM.Company objCompany = null;
            int    intResult       = -1;
            string strErrorMessage = "";
            bool   blConnect       = false;

            try
            {
                _Logger.Debug("Retreiving connection information from Cache: " + b1ConnectionInfo.ConnectionName);
                objCompany = T1.CacheManager.CacheManager.Instance.getFromCache(b1ConnectionInfo.ConnectionName);
                if (objCompany != null)
                {
                    if (!objCompany.Connected)
                    {
                        blConnect = true;
                        T1.CacheManager.CacheManager.Instance.removeFromCache(b1ConnectionInfo.ConnectionName);
                    }
                }
                else
                {
                    blConnect = true;
                }

                if (blConnect)
                {
                    _Logger.Debug("Starting to Connect to B1 Company");
                    objCompany               = new SAPbobsCOM.Company();
                    objCompany.Server        = b1ConnectionInfo.Server;
                    objCompany.LicenseServer = b1ConnectionInfo.LicenseServer;
                    objCompany.DbServerType  = b1ConnectionInfo.B1DBServerType;
                    objCompany.CompanyDB     = b1ConnectionInfo.CompanyDB;
                    objCompany.DbUserName    = b1ConnectionInfo.DBUserName;
                    objCompany.DbPassword    = b1ConnectionInfo.DBUserPassword;
                    objCompany.UserName      = b1ConnectionInfo.B1UserName;
                    objCompany.Password      = b1ConnectionInfo.B1Password;
                    intResult = objCompany.Connect();
                    if (intResult == 0)
                    {
                        _Logger.Debug("Conected to: " + objCompany.CompanyName);
                        T1.CacheManager.CacheManager.Instance.addToCache(b1ConnectionInfo.ConnectionName, objCompany, T1.CacheManager.CacheManager.objCachePriority.NotRemovable);
                    }
                    else
                    {
                        strErrorMessage = objCompany.GetLastErrorDescription();
                        _Logger.Error(strErrorMessage);
                    }
                }
            }
            catch (COMException comEx)
            {
                strErrorMessage = "COM Error::" + comEx.ErrorCode + "::" + comEx.Message + "::" + comEx.StackTrace;
                _Logger.Error(strErrorMessage, comEx);
            }
            catch (Exception er)
            {
                _Logger.Error("", er);
            }
        }
예제 #22
0
파일: B1_UI.cs 프로젝트: Fun33/code
    private int ConnectToCompany()
    {
        int connectToCompanyReturn = 0;

        // // Establish the connection to the company database.
        connectToCompanyReturn = oCompany.Connect();

        return(connectToCompanyReturn);
    }
예제 #23
0
        private void ConnectSBO(ref int nErr, ref string sErr)
        {
            sErr = "";
            nErr = 0;

            Llacolen_SBOService.Properties.Settings.Default.Reload();
            // Set connection properties
            if (Llacolen_SBOService.Properties.Settings.Default.SQLType == 2005)
            {
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005;
            }
            else if (Llacolen_SBOService.Properties.Settings.Default.SQLType == 2008)
            {
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008;
            }
            else if (Llacolen_SBOService.Properties.Settings.Default.SQLType == 2012)
            {
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
            }
            else if (Llacolen_SBOService.Properties.Settings.Default.SQLType == 2014)
            {
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014;
            }
            else if (Llacolen_SBOService.Properties.Settings.Default.SQLType == 2016)
            {
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016;
            }

            oCompany.Server     = Llacolen_SBOService.Properties.Settings.Default.Server;
            oCompany.UseTrusted = false;
            oCompany.DbUserName = Llacolen_SBOService.Properties.Settings.Default.DBUserName;
            oCompany.DbPassword = Llacolen_SBOService.Properties.Settings.Default.DBPassword;

            oCompany.CompanyDB = Llacolen_SBOService.Properties.Settings.Default.CompanyDB;
            oCompany.UserName  = Llacolen_SBOService.Properties.Settings.Default.UserName;
            oCompany.Password  = Llacolen_SBOService.Properties.Settings.Default.Password;

            //Try to connect
            nErr = oCompany.Connect();

            if (nErr != 0) // if the connection failed
            {
                oCompany.GetLastError(out nErr, out sErr);
            }
            else
            {
                sErr = "OK";
            }

            oLog.LogMsg("Conexión SBO " + sErr, "F", "I");
        }
예제 #24
0
        public static void Login()
        {
            curCompany = new SAPbobsCOM.Company();
            curCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008;
            //curCompany.LicenseServer = "192.168.3.222:30000";
            //
            curCompany.Server    = "LYQ-ACE9616F909";
            curCompany.CompanyDB = "Olin_Test5";
            curCompany.UserName  = "******";
            curCompany.Password  = "******";

            int    conRetVal         = curCompany.Connect();
            string conRetValErrorMsg = curCompany.GetLastErrorDescription();
        }
예제 #25
0
        SAPbobsCOM.Company CompanyConnectTest()
        {
            try
            {
                SAPbobsCOM.Company Company = new SAPbobsCOM.Company();
                Company.DbServerType  = (SAPbobsCOM.BoDataServerTypes)System.Enum.Parse(typeof(SAPbobsCOM.BoDataServerTypes), this.cmbB1Type.Text);
                Company.Server        = this.txtDBServer.Text;
                Company.DbUserName    = this.txtDBUser.Text;
                Company.DbPassword    = this.txtDBPassword.Text;
                Company.CompanyDB     = this.cmbDBName.Text;
                Company.UserName      = this.txtB1User.Text;
                Company.Password      = this.txtB1Password.Text;
                Company.LicenseServer = this.txtB1Server.Text;
                SAPbobsCOM.BoSuppLangs language;
                if (System.Enum.TryParse <SAPbobsCOM.BoSuppLangs>(this.cmbLanguage.Text, out language))
                {
                    Company.language = language;
                }

                int ret = Company.Connect();
                if (ret != 0)
                {
                    throw new Exception(string.Format("连接B1失败,{0}", Company.GetLastErrorDescription()));
                }
                return(Company);
            }
            catch (Exception ex)
            {
                string message = string.Format("[DI API]初始化失败");
                if ((ex) is System.IO.FileNotFoundException & ex.Message.IndexOf("632F4591-AA62-4219-8FB6-22BCF5F60090") > 0)
                {
                    string msg_no_di = string.Format("{0},{1}", message, "可能是此计算机没有安装匹配的{0}位版本DI。");
                    if ((System.Environment.Is64BitProcess))
                    {
                        //'64位客户端
                        message = string.Format(msg_no_di, "64");
                    }
                    else
                    {
                        //'32位客户端
                        message = string.Format(msg_no_di, "32");
                    }
                }
                else
                {
                    message = string.Format("{0},{1}", message, ex.Message);
                }
                throw new Exception(message, ex);
            }
        }
        public static SAPbobsCOM.Company InitializeCompany()
        {
            try
            {
                //Log.WriteLog("Inicializando conexão com o BD e SAP.");

                oCompany = new SAPbobsCOM.Company
                {
                    Server       = ConfigurationManager.AppSettings["Server"],
                    language     = SAPbobsCOM.BoSuppLangs.ln_English,
                    UseTrusted   = false,
                    DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2016,
                    CompanyDB    = ConfigurationManager.AppSettings["DataBase"],
                    UserName     = ConfigurationManager.AppSettings["SapUser"],
                    Password     = ConfigurationManager.AppSettings["SapPassword"],
                    DbUserName   = ConfigurationManager.AppSettings["DbUser"],
                    DbPassword   = ConfigurationManager.AppSettings["DbPassword"],
                    //LicenseServer = "sapsrv:30000"
                };

                if (oCompany.Connected == true)
                {
                    oCompany.Disconnect();
                }

                long lRetCode = oCompany.Connect();

                if (lRetCode != 0)
                {
                    int    temp_int    = 0;
                    string temp_string = "";
                    oCompany.GetLastError(out temp_int, out temp_string);

                    //Log.WriteLog("InitializeCompany Error: " + temp_string);
                    return(oCompany);
                }
                else
                {
                    //Log.WriteLog("Conexão realizada com sucesso.");
                    return(oCompany);
                    //Inserir na tabela de log
                }
            }
            catch (System.Exception e)
            {
                //Log.WriteLog("InitializeCompany Exception: "+e.Message);
                throw e;
            }
        }
예제 #27
0
 public void Connecting(out string message)
 {
     message = string.Empty;
     if (company.Connected)
     {
         company.Disconnect();
     }
     if (!company.Connected)
     {
         if (company.Connect() != 0)
         {
             message = company.GetLastErrorDescription();
         }
     }
 }
예제 #28
0
    public bool connect()
    {
        try
        {
            oSetupCompany = new SAPbobsCOM.Company();

            /*
             * txtServer.Text = @"SIMON-PC\MSSQL2014";
             * txtUser.Text = "sa";
             * txtPass.Text = "Hsyhmin1";
             * txtSBOPass.Text = "Hsyhmin1";
             */


            // once the Server property of the Company is set
            // we may query for a list of companies to choos from
            // this method returns a Recordset object

            oSetupCompany.language      = SAPbobsCOM.BoSuppLangs.ln_English;
            oSetupCompany.Server        = txtServer;
            oSetupCompany.CompanyDB     = txtDBName;
            oSetupCompany.DbUserName    = txtDBUser;
            oSetupCompany.DbPassword    = txtDBPass;
            oSetupCompany.UserName      = txtSBOUser;
            oSetupCompany.Password      = txtSBOPass;
            oSetupCompany.LicenseServer = txtLicenseServer;
            oSetupCompany.DbServerType  = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
            lRetCode = oSetupCompany.Connect();
            if (lRetCode != 0)
            {
                oSetupCompany.GetLastError(out lErrCode, out sErrMsg);
                lastError = string.Format("Cannot connect to the company DB.\r\n\r\nLicense Server: {0}\r\nDB Server: {1}\r\nB1 User:{3}\r\nB1 User Pwd:{4}\r\nDB User:{5}\r\nDB User Pwd{6}\r\nError:{2}"
                                          , oSetupCompany.LicenseServer, oSetupCompany.Server, sErrMsg
                                          , txtSBOUser, txtSBOPass, txtDBUser, txtDBPass);
                errorLog(lastError);
                return(false);
            }
            else
            {
                errorLog("Connected to " + oSetupCompany.CompanyName);
                return(true);
            }
        }catch (Exception ex)
        {
            errorLog(ex);
        }
        return(false);
    }
예제 #29
0
        public static SAPbobsCOM.Company getConnessione()
        {
            SAPbobsCOM.Company c;
            c               = new SAPbobsCOM.Company();
            c.Server        = ConfigurationManager.AppSettings["Server"].ToString();
            c.DbServerType  = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
            c.LicenseServer = ConfigurationManager.AppSettings["LicenseServer"].ToString();
            c.DbUserName    = ConfigurationManager.AppSettings["DbUserName"].ToString();
            c.DbPassword    = ConfigurationManager.AppSettings["DbPassword"].ToString();
            c.UserName      = ConfigurationManager.AppSettings["UserName"].ToString();
            c.Password      = ConfigurationManager.AppSettings["Password"].ToString();
            c.CompanyDB     = ConfigurationManager.AppSettings["CompanyDB"].ToString();
            c.Connect();

            return(c);
        }
예제 #30
0
    public static SAPbobsCOM.Company SAPConnection(string dftDBName, string SAPUser, string SAPPass, out bool isConnected, out string _ErrorMsg)
    {
        int lRetCode;

        SAPbobsCOM.Company newCompany;
        newCompany = new SAPbobsCOM.Company();

        newCompany.LicenseServer = ConfigurationManager.AppSettings["sysLicenseServer"];

        newCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
        newCompany.Server       = ConfigurationManager.AppSettings["sysDBServer"];
        newCompany.DbUserName   = ConfigurationManager.AppSettings["sysDBUsername"];
        newCompany.DbPassword   = ConfigurationManager.AppSettings["sysDBPassword"];

        //oCompany.CompanyDB = ConfigurationManager.AppSettings["sysDftDBCompany"];
        //oCompany.UserName = ConfigurationManager.AppSettings["sysSAPUsername"];
        //oCompany.Password = ConfigurationManager.AppSettings["sysSAPPassword"];

        newCompany.CompanyDB = dftDBName;
        newCompany.UserName  = SAPUser;
        newCompany.Password  = SAPPass;

        newCompany.language = SAPbobsCOM.BoSuppLangs.ln_English;


        lRetCode = newCompany.Connect();
        //DIErrorHandler(lRetCode, "Connecting To SAP", "SAP Connection");

        string sErrMsg;
        int    lErrCode;

        if (lRetCode != 0)
        {
            newCompany.GetLastError(out lErrCode, out sErrMsg);
            _ErrorMsg   = lErrCode + " " + sErrMsg;
            isConnected = false;
        }
        else
        {
            _ErrorMsg   = "Conneted To SAP";
            isConnected = true;
        }

        return(newCompany);
        //return
    }
예제 #31
0
        public SAPbobsCOM.Company ConnectToTargetCompany(SAPbobsCOM.Company oCompany, string sUserName, string sPassword, string sDBName,
            string sServer, string sLicServerName, string sDBUserName
            , string sDBPassword, string sErrDesc)
        {
            string sFuncName = string.Empty;
            //SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
            long lRetCode;

            try
            {
                sFuncName = "ConnectToTargetCompany()";

                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Starting Function ", sFuncName);

                if (oCompany != null)
                {
                    if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Disconnecting the Company object - Company Name " + oCompany.CompanyName, sFuncName);
                    oCompany.Disconnect();
                }
                oCompany = new SAPbobsCOM.Company();
                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("After Initializing Company Connection ", sFuncName);
                oCompany.Server = sServer;
                oCompany.LicenseServer = sLicServerName;
                oCompany.DbUserName = sDBUserName;
                oCompany.DbPassword = sDBPassword;
                oCompany.language = SAPbobsCOM.BoSuppLangs.ln_English;
                oCompany.UseTrusted = false;
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;

                oCompany.CompanyDB = sDBName;// sDataBaseName;
                oCompany.UserName = sUserName;
                oCompany.Password = sPassword;

                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Connecting the Database...", sFuncName);

                lRetCode = oCompany.Connect();

                if (lRetCode != 0)
                {

                    throw new ArgumentException(oCompany.GetLastErrorDescription());
                }
                else
                {
                    if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Company Connection Established", sFuncName);
                    if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With SUCCESS", sFuncName);
                    return oCompany;
                }

            }
            catch (Exception Ex)
            {

                sErrDesc = Ex.Message.ToString();
                if (p_iDebugMode == DEBUG_ON) oLog.WriteToErrorLogFile(sErrDesc, sFuncName);
                if (p_iDebugMode == DEBUG_ON) oLog.WriteToDebugLogFile("Completed With ERROR  ", sFuncName);
                throw Ex;
            }
        }