Пример #1
0
        private void CreateTextDsn(SystemDSN dsn)
        {
            // get driver path
            string driver = GetDriverPath(TEXT_DRIVER);

            // add ODBC name
            RegisterDSN(dsn.Name, TEXT_DRIVER);

            // add ODBC tree
            RegistryKey keyDsn = CreateDSNNode(dsn.Name);

            keyDsn.SetValue("Driver", driver);
            keyDsn.SetValue("Description", DSN_DESCRIPTION);
            keyDsn.SetValue("DefaultDir", dsn.DatabaseName);
            keyDsn.SetValue("DriverId", 27);
            keyDsn.SetValue("FIL", "text;");
            keyDsn.SetValue("SafeTransactions", 0);
            keyDsn.SetValue("UID", "");

            // add "Engines/Text" subkey
            RegistryKey keyEngines = keyDsn.CreateSubKey("Engines");
            RegistryKey keyText    = keyEngines.CreateSubKey("Text");

            keyText.SetValue("ImplicitCommitSync", "");
            keyText.SetValue("Threads", 3);
            keyText.SetValue("UserCommitSync", "Yes");

            keyText.Close();
            keyEngines.Close();
            keyDsn.Close();
        }
Пример #2
0
        public virtual void CreateDSN(SystemDSN dsn)
        {
            switch (dsn.Driver.ToLower())
            {
            case "mssql":
                CreateMsSqlDsn(dsn, MSSQL_DRIVER);
                break;

            case "mssqlnative":
                CreateMsSqlDsn(dsn, MSSQL_NATIVE_DRIVER);
                break;

            case "mysql":
                CreateMySqlDsn(dsn);
                break;

            case "msaccess":
                CreateMsAccessDsn(dsn);
                break;

            case "excel":
                CreateExcelDsn(dsn);
                break;

            case "text":
                CreateTextDsn(dsn);
                break;
            }
        }
Пример #3
0
        private void CreateMsAccessDsn(SystemDSN dsn)
        {
            // get driver path
            string driver = GetDriverPath(MSACCESS_DRIVER);

            // add ODBC name
            RegisterDSN(dsn.Name, MSACCESS_DRIVER);

            // add ODBC tree
            RegistryKey keyDsn = CreateDSNNode(dsn.Name);

            keyDsn.SetValue("Driver", driver);
            keyDsn.SetValue("Description", DSN_DESCRIPTION);
            keyDsn.SetValue("DBQ", dsn.DatabaseName);
            keyDsn.SetValue("DriverId", 25);
            keyDsn.SetValue("FIL", "MS Access;");
            keyDsn.SetValue("SafeTransactions", 0);
            keyDsn.SetValue("UID", dsn.DatabaseUser);
            keyDsn.SetValue("PWD", dsn.DatabasePassword);

            // add "Engines/Jet" subkey
            RegistryKey keyEngines = keyDsn.CreateSubKey("Engines");
            RegistryKey keyJet     = keyEngines.CreateSubKey("Jet");

            keyJet.SetValue("ImplicitCommitSync", "");
            keyJet.SetValue("MaxBufferSize", 2048);
            keyJet.SetValue("PageTimeout", 5);
            keyJet.SetValue("Threads", 3);
            keyJet.SetValue("UserCommitSync", "Yes");

            keyJet.Close();
            keyEngines.Close();
            keyDsn.Close();
        }
Пример #4
0
        private void CreateExcelDsn(SystemDSN dsn)
        {
            // get driver path
            string driver = GetDriverPath(MSEXCEL_DRIVER);

            // add ODBC name
            RegisterDSN(dsn.Name, MSEXCEL_DRIVER);

            // add ODBC tree
            RegistryKey keyDsn = CreateDSNNode(dsn.Name);

            keyDsn.SetValue("Driver", driver);
            keyDsn.SetValue("Description", DSN_DESCRIPTION);
            keyDsn.SetValue("DBQ", dsn.DatabaseName);
            keyDsn.SetValue("DefaultDir", Path.GetDirectoryName(dsn.DatabaseName));
            keyDsn.SetValue("DriverId", 790);
            keyDsn.SetValue("FIL", "excel 8.0;");
            keyDsn.SetValue("SafeTransactions", 0);
            keyDsn.SetValue("UID", "");
            keyDsn.SetValue("ReadOnly", new byte[] { 1 });

            // add "Engines/Excel" subkey
            RegistryKey keyEngines = keyDsn.CreateSubKey("Engines");
            RegistryKey keyExcel   = keyEngines.CreateSubKey("Excel");

            keyExcel.SetValue("ImplicitCommitSync", "");
            keyExcel.SetValue("MaxScanRows", 8);
            keyExcel.SetValue("FirstRowHasNames", new byte[] { 1 });
            keyExcel.SetValue("Threads", 3);
            keyExcel.SetValue("UserCommitSync", "Yes");

            keyExcel.Close();
            keyEngines.Close();
            keyDsn.Close();
        }
Пример #5
0
        public virtual void UpdateDSN(SystemDSN dsn)
        {
            // delete DSN
            DeleteDSN(dsn.Name);

            // create again
            CreateDSN(dsn);
        }
Пример #6
0
        private void CreateMsSqlDsn(SystemDSN dsn, string driverName)
        {
            // get driver path
            string driver = GetDriverPath(driverName);

            // add ODBC name
            RegisterDSN(dsn.Name, driverName);

            // add ODBC tree
            RegistryKey keyDsn = CreateDSNNode(dsn.Name);

            keyDsn.SetValue("Server", dsn.DatabaseServer);
            keyDsn.SetValue("Driver", driver);
            keyDsn.SetValue("Description", DSN_DESCRIPTION);
            keyDsn.SetValue("Database", dsn.DatabaseName);
            keyDsn.SetValue("LastUser", dsn.DatabaseUser);
            keyDsn.Close();
        }
Пример #7
0
        private void CreateMySqlDsn(SystemDSN dsn)
        {
            // get driver path
            string driver = GetDriverPath(MYSQL_DRIVER);

            // add ODBC name
            RegisterDSN(dsn.Name, MYSQL_DRIVER);

            // add ODBC tree
            RegistryKey keyDsn = CreateDSNNode(dsn.Name);

            keyDsn.SetValue("SERVER", dsn.DatabaseServer);
            keyDsn.SetValue("Driver", driver);
            keyDsn.SetValue("DESCRIPTION", DSN_DESCRIPTION);
            keyDsn.SetValue("DATABASE", dsn.DatabaseName);
            keyDsn.SetValue("UID", dsn.DatabaseUser);
            keyDsn.SetValue("PWD", dsn.DatabasePassword);
            keyDsn.Close();
        }
 /// <remarks/>
 public System.IAsyncResult BeginUpdateOdbcSource(SystemDSN item, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("UpdateOdbcSource", new object[] {
                 item}, callback, asyncState);
 }
 /// <remarks/>
 public void UpdateOdbcSourceAsync(SystemDSN item)
 {
     this.UpdateOdbcSourceAsync(item, null);
 }
Пример #10
0
 /// <remarks/>
 public void AddOdbcSourceAsync(SystemDSN item)
 {
     this.AddOdbcSourceAsync(item, null);
 }
Пример #11
0
 public int UpdateOdbcSource(SystemDSN item)
 {
     object[] results = this.Invoke("UpdateOdbcSource", new object[] {
                 item});
     return ((int)(results[0]));
 }
Пример #12
0
 /// <remarks/>
 public System.IAsyncResult BeginUpdateDSN(SystemDSN dsn, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("UpdateDSN", new object[] {
                 dsn}, callback, asyncState);
 }
Пример #13
0
 public virtual void CreateDSN(SystemDSN dsn)
 {
     switch (dsn.Driver.ToLower())
     {
         case "mssql":
             CreateMsSqlDsn(dsn, MSSQL_DRIVER);
             break;
         case "mssqlnative":
             CreateMsSqlDsn(dsn, MSSQL_NATIVE_DRIVER);
             break;
         case "mysql":
             CreateMySqlDsn(dsn);
             break;
         case "msaccess":
             CreateMsAccessDsn(dsn);
             break;
         case "excel":
             CreateExcelDsn(dsn);
             break;
         case "text":
             CreateTextDsn(dsn);
             break;
     }
 }
Пример #14
0
        private void BindItem()
        {
            try
            {
                if (!IsPostBack)
                {
                    string[] supportedDrivers = null;
                    ArrayList drivers = null;
                    
                    
                    // load item if required
                    if (PanelRequest.ItemID > 0)
                    {
                        // existing item
                        try
                        {
                            item = ES.Services.OperatingSystems.GetOdbcSource(PanelRequest.ItemID);
                        }
                        catch (Exception ex)
                        {
                            ShowErrorMessage("DSN_GET", ex);
                            return;
                        }

                        if (item != null)
                        {
                            // save package info
                            ViewState["PackageId"] = item.PackageId;
                            fileLookup.PackageId = item.PackageId;
                            dsnName.SetPackagePolicy(item.PackageId, UserSettings.OS_POLICY, "DsnNamePolicy");
                            supportedDrivers = ES.Services.OperatingSystems.GetInstalledOdbcDrivers(item.PackageId);
                        }
                        else
                            RedirectToBrowsePage();
                    }
                    else
                    {
                        // new item
                        bool isMsSQLavailable = false;
                        ViewState["PackageId"] = PanelSecurity.PackageId;
                        dsnName.SetPackagePolicy(PanelSecurity.PackageId, UserSettings.OS_POLICY, "DsnNamePolicy");
                        fileLookup.PackageId = PanelSecurity.PackageId;
                        fileLookup.SelectedFile = "\\";
                        supportedDrivers = ES.Services.OperatingSystems.GetInstalledOdbcDrivers(PanelSecurity.PackageId);
                        PackageInfo pack = ES.Services.Packages.GetPackage(PanelSecurity.PackageId);
                        HostingPlanContext cont = ES.Services.Packages.GetHostingPlanContext(pack.PlanId);
                        HostingPlanGroupInfo[] groups = cont.GroupsArray;
                        foreach (HostingPlanGroupInfo info in (groups))
                        {
                            if (info.GroupName.Contains("MsSQL"))
                                isMsSQLavailable = true;
                        }
                        drivers = new ArrayList(supportedDrivers);
                        if (!isMsSQLavailable)
                        {
                            //remove unnecessary drivers from list if MS SQL Server is not available in Hosting Plan
                            drivers.Remove("MsSql");
                            drivers.Remove("MsSqlNative");
                        }
                        
                    }

                    // bind drivers
                    if (supportedDrivers != null)
                        foreach (string driver in supportedDrivers)
                            ddlDriver.Items.Add(new ListItem(driver, driver));

                    ToggleDriverControls(ddlDriver.SelectedValue);
                }

                if (!IsPostBack)
                {
                    // bind item to controls
                    if (item != null)
                    {
                        // bind item to controls
                        passwordControl.EditMode = true;
                        fileLookup.PackageId = item.PackageId;
                        dsnName.Text = item.Name;
                        dsnName.EditMode = true;
                        Utils.SelectListItem(ddlDriver, item.Driver);
                        ddlDriver.Enabled = false;
                        ddlDatabaseName.Enabled = false;
                        ddlDatabaseUser.Enabled = false;

                        ToggleDriverControls(ddlDriver.SelectedValue);

                        // database
                        string driverName = item.Driver;

                        if (driverName == "MsSql" || driverName == "MsSqlNative" || driverName == "MySql")
                        {
                            // unselect currently selected item
                            if (ddlDatabaseName.SelectedIndex != -1)
                                ddlDatabaseName.SelectedItem.Selected = false;

                            foreach (ListItem li in ddlDatabaseName.Items)
                            {
                                if (li.Value.StartsWith(item.DatabaseName + "|"))
                                {
                                    li.Selected = true;
                                    break;
                                }
                            }
                        }
                        else
                            fileLookup.SelectedFile = item.DatabaseName;

                        // user
                        if (driverName == "MsAccess")
                            txtUser.Text = item.DatabaseUser;
                        else
                            Utils.SelectListItem(ddlDatabaseUser, item.DatabaseUser);
                    }
                }
            }
            catch
            {
                ShowWarningMessage("INIT_SERVICE_ITEM_FORM");
                DisableFormControls(this, btnCancel);
            }
        }
Пример #15
0
 /// <remarks/>
 public void UpdateDSNAsync(SystemDSN dsn, object userState) {
     if ((this.UpdateDSNOperationCompleted == null)) {
         this.UpdateDSNOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateDSNOperationCompleted);
     }
     this.InvokeAsync("UpdateDSN", new object[] {
                 dsn}, this.UpdateDSNOperationCompleted, userState);
 }
Пример #16
0
        private void CreateMsAccessDsn(SystemDSN dsn)
        {
            // get driver path
            string driver = GetDriverPath(MSACCESS_DRIVER);

            // add ODBC name
            RegisterDSN(dsn.Name, MSACCESS_DRIVER);

            // add ODBC tree
            RegistryKey keyDsn = CreateDSNNode(dsn.Name);
            keyDsn.SetValue("Driver", driver);
            keyDsn.SetValue("Description", DSN_DESCRIPTION);
            keyDsn.SetValue("DBQ", dsn.DatabaseName);
            keyDsn.SetValue("DriverId", 25);
            keyDsn.SetValue("FIL", "MS Access;");
            keyDsn.SetValue("SafeTransactions", 0);
            keyDsn.SetValue("UID", dsn.DatabaseUser);
            keyDsn.SetValue("PWD", dsn.DatabasePassword);

            // add "Engines/Jet" subkey
            RegistryKey keyEngines = keyDsn.CreateSubKey("Engines");
            RegistryKey keyJet = keyEngines.CreateSubKey("Jet");
            keyJet.SetValue("ImplicitCommitSync", "");
            keyJet.SetValue("MaxBufferSize", 2048);
            keyJet.SetValue("PageTimeout", 5);
            keyJet.SetValue("Threads", 3);
            keyJet.SetValue("UserCommitSync", "Yes");

            keyJet.Close();
            keyEngines.Close();
            keyDsn.Close();
        }
Пример #17
0
        private void CreateExcelDsn(SystemDSN dsn)
        {
            // get driver path
            string driver = GetDriverPath(MSEXCEL_DRIVER);

            // add ODBC name
            RegisterDSN(dsn.Name, MSEXCEL_DRIVER);

            // add ODBC tree
            RegistryKey keyDsn = CreateDSNNode(dsn.Name);
            keyDsn.SetValue("Driver", driver);
            keyDsn.SetValue("Description", DSN_DESCRIPTION);
            keyDsn.SetValue("DBQ", dsn.DatabaseName);
            keyDsn.SetValue("DefaultDir", Path.GetDirectoryName(dsn.DatabaseName));
            keyDsn.SetValue("DriverId", 790);
            keyDsn.SetValue("FIL", "excel 8.0;");
            keyDsn.SetValue("SafeTransactions", 0);
            keyDsn.SetValue("UID", "");
            keyDsn.SetValue("ReadOnly", new byte[] { 1 });

            // add "Engines/Excel" subkey
            RegistryKey keyEngines = keyDsn.CreateSubKey("Engines");
            RegistryKey keyExcel = keyEngines.CreateSubKey("Excel");
            keyExcel.SetValue("ImplicitCommitSync", "");
            keyExcel.SetValue("MaxScanRows", 8);
            keyExcel.SetValue("FirstRowHasNames", new byte[] { 1 });
            keyExcel.SetValue("Threads", 3);
            keyExcel.SetValue("UserCommitSync", "Yes");

            keyExcel.Close();
            keyEngines.Close();
            keyDsn.Close();
        }
Пример #18
0
        private void CreateMySqlDsn(SystemDSN dsn)
        {
            // get driver path
            string driver = GetDriverPath(MYSQL_DRIVER);

            // add ODBC name
            RegisterDSN(dsn.Name, MYSQL_DRIVER);

            // add ODBC tree
            RegistryKey keyDsn = CreateDSNNode(dsn.Name);
            keyDsn.SetValue("SERVER", dsn.DatabaseServer);
            keyDsn.SetValue("Driver", driver);
            keyDsn.SetValue("DESCRIPTION", DSN_DESCRIPTION);
            keyDsn.SetValue("DATABASE", dsn.DatabaseName);
            keyDsn.SetValue("UID", dsn.DatabaseUser);
            keyDsn.SetValue("PWD", dsn.DatabasePassword);
            keyDsn.Close();
        }
Пример #19
0
        private void CreateMsSqlDsn(SystemDSN dsn, string driverName)
        {
            // get driver path
            string driver = GetDriverPath(driverName);

            // add ODBC name
            RegisterDSN(dsn.Name, driverName);

            // add ODBC tree
            RegistryKey keyDsn = CreateDSNNode(dsn.Name);
            keyDsn.SetValue("Server", dsn.DatabaseServer);
            keyDsn.SetValue("Driver", driver);
            keyDsn.SetValue("Description", DSN_DESCRIPTION);
            keyDsn.SetValue("Database", dsn.DatabaseName);
            keyDsn.SetValue("LastUser", dsn.DatabaseUser);
            keyDsn.Close();
        }
Пример #20
0
        public virtual void UpdateDSN(SystemDSN dsn)
        {
            // delete DSN
            DeleteDSN(dsn.Name);

            // create again
            CreateDSN(dsn);
        }
Пример #21
0
 /// <remarks/>
 public void UpdateOdbcSourceAsync(SystemDSN item, object userState)
 {
     if ((this.UpdateOdbcSourceOperationCompleted == null))
     {
         this.UpdateOdbcSourceOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateOdbcSourceOperationCompleted);
     }
     this.InvokeAsync("UpdateOdbcSource", new object[] {
                 item}, this.UpdateOdbcSourceOperationCompleted, userState);
 }
Пример #22
0
        private void SaveItem()
        {
            if (!Page.IsValid)
                return;

            // get form data
            SystemDSN item = new SystemDSN();
            item.Id = PanelRequest.ItemID;
            item.PackageId = PanelSecurity.PackageId;
            item.Name = dsnName.Text.Trim();
            item.DatabasePassword = passwordControl.Password;

            // database
            string driverName = ddlDriver.SelectedValue;
            item.Driver = driverName;

            if (driverName == "MsSql" || driverName == "MsSqlNative" || driverName == "MySql")
                item.DatabaseName = ddlDatabaseName.SelectedValue;
            else
                item.DatabaseName = fileLookup.SelectedFile;

            // user
            if (driverName == "MsAccess")
                item.DatabaseUser = txtUser.Text.Trim();
            else
                item.DatabaseUser = ddlDatabaseUser.SelectedValue;

            if (PanelRequest.ItemID == 0)
            {
                try
                {
                    // new item
                    int result = ES.Services.OperatingSystems.AddOdbcSource(item);
                    if (result < 0)
                    {
                        ShowResultMessage(result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("DSN_ADD", ex);
                    return;
                }
            }
            else
            {
                try
                {
                    // existing item
                    int result = ES.Services.OperatingSystems.UpdateOdbcSource(item);
                    if (result < 0)
                    {
                        ShowResultMessage(result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("DSN_UPDATE", ex);
                    return;
                }
            }

            // return
            RedirectSpaceHomePage();
        }
Пример #23
0
        public virtual SystemDSN GetDSN(string dsnName)
        {
            // check DSN name
            RegistryKey keyNames = Registry.LocalMachine.OpenSubKey(ODBC_NAMES_KEY);

            if (keyNames == null)
            {
                return(null);
            }

            string driverName = (string)keyNames.GetValue(dsnName);

            if (driverName == null)
            {
                return(null);
            }

            // open DSN tree
            RegistryKey keyDsn = Registry.LocalMachine.OpenSubKey(ODBC_SOURCES_KEY + "\\" + dsnName);

            if (keyDsn == null)
            {
                return(null);
            }

            SystemDSN dsn = new SystemDSN();

            dsn.Name = dsnName;
            if (driverName == MSSQL_DRIVER || driverName == MSSQL_NATIVE_DRIVER)
            {
                dsn.Driver         = (driverName == MSSQL_DRIVER) ? "MsSql" : "MsSqlNative";
                dsn.DatabaseServer = (string)keyDsn.GetValue("Server");
                dsn.DatabaseName   = (string)keyDsn.GetValue("Database");
                dsn.DatabaseUser   = (string)keyDsn.GetValue("LastUser");
            }
            else if (driverName.ToLower().StartsWith(MYSQL_DRIVER.ToLower()))
            {
                dsn.Driver           = "MySql";
                dsn.DatabaseServer   = (string)keyDsn.GetValue("SERVER");
                dsn.DatabaseName     = (string)keyDsn.GetValue("DATABASE");
                dsn.DatabaseUser     = (string)keyDsn.GetValue("UID");
                dsn.DatabasePassword = (string)keyDsn.GetValue("PWD");
            }
            else if (driverName == MSACCESS_DRIVER)
            {
                dsn.Driver           = "MsAccess";
                dsn.DatabaseName     = (string)keyDsn.GetValue("DBQ");
                dsn.DatabaseUser     = (string)keyDsn.GetValue("UID");
                dsn.DatabasePassword = (string)keyDsn.GetValue("PWD");
            }
            else if (driverName == MSEXCEL_DRIVER)
            {
                dsn.Driver       = "Excel";
                dsn.DatabaseName = (string)keyDsn.GetValue("DBQ");
            }
            else if (driverName == TEXT_DRIVER)
            {
                dsn.Driver       = "Text";
                dsn.DatabaseName = (string)keyDsn.GetValue("DefaultDir");
            }

            return(dsn);
        }
        public static int UpdateOdbcSource(SystemDSN item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // load original meta item
            SystemDSN origItem = (SystemDSN)PackageController.GetPackageItem(item.Id);
            if (origItem == null)
                return BusinessErrorCodes.ERROR_OS_DSN_PACKAGE_ITEM_NOT_FOUND;

            // check package
            int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive);
            if (packageCheck < 0) return packageCheck;

            // place log record
            TaskManager.StartTask("ODBC_DSN", "UPDATE", origItem.Name, item.Id);

            try
            {
                // get service
                OS.OperatingSystem os = GetOS(origItem.ServiceId);

                // password
                item.Driver = origItem.Driver;
                item.Name = origItem.Name;

                if (item.DatabasePassword == "")
                    item.DatabasePassword = CryptoUtils.Decrypt(origItem.DatabasePassword);

                string[] dbNameParts = item.DatabaseName.Split('|');
                string groupName = null;
                if (dbNameParts.Length > 1)
                {
                    item.DatabaseName = dbNameParts[0];
                    groupName = dbNameParts[1];
                }

                // get database server address
                item.DatabaseServer = GetDatabaseServerName(groupName, item.PackageId);

                if (item.Driver == "MsAccess" || item.Driver == "Excel" || item.Driver == "Text")
                    item.DatabaseName = FilesController.GetFullPackagePath(origItem.PackageId, item.DatabaseName);

                // update service item
                os.UpdateDSN(item);

                // update meta item
                if (item.DatabasePassword != "")
                {
                    item.DatabasePassword = CryptoUtils.Encrypt(item.DatabasePassword);
                    PackageController.UpdatePackageItem(item);
                }

                return 0;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Пример #25
0
 /// <remarks/>
 public void UpdateDSNAsync(SystemDSN dsn) {
     this.UpdateDSNAsync(dsn, null);
 }
Пример #26
0
 public void UpdateDSN(SystemDSN dsn) {
     this.Invoke("UpdateDSN", new object[] {
                 dsn});
 }
Пример #27
0
        private void CreateTextDsn(SystemDSN dsn)
        {
            // get driver path
            string driver = GetDriverPath(TEXT_DRIVER);

            // add ODBC name
            RegisterDSN(dsn.Name, TEXT_DRIVER);

            // add ODBC tree
            RegistryKey keyDsn = CreateDSNNode(dsn.Name);
            keyDsn.SetValue("Driver", driver);
            keyDsn.SetValue("Description", DSN_DESCRIPTION);
            keyDsn.SetValue("DefaultDir", dsn.DatabaseName);
            keyDsn.SetValue("DriverId", 27);
            keyDsn.SetValue("FIL", "text;");
            keyDsn.SetValue("SafeTransactions", 0);
            keyDsn.SetValue("UID", "");

            // add "Engines/Text" subkey
            RegistryKey keyEngines = keyDsn.CreateSubKey("Engines");
            RegistryKey keyText = keyEngines.CreateSubKey("Text");
            keyText.SetValue("ImplicitCommitSync", "");
            keyText.SetValue("Threads", 3);
            keyText.SetValue("UserCommitSync", "Yes");

            keyText.Close();
            keyEngines.Close();
            keyDsn.Close();
        }
Пример #28
0
        public virtual SystemDSN GetDSN(string dsnName)
        {
            // check DSN name
            RegistryKey keyNames = Registry.LocalMachine.OpenSubKey(ODBC_NAMES_KEY);
            if (keyNames == null)
                return null;

            string driverName = (string)keyNames.GetValue(dsnName);
            if (driverName == null)
                return null;

            // open DSN tree
            RegistryKey keyDsn = Registry.LocalMachine.OpenSubKey(ODBC_SOURCES_KEY + "\\" + dsnName);
            if (keyDsn == null)
                return null;

            SystemDSN dsn = new SystemDSN();
            dsn.Name = dsnName;
            if (driverName == MSSQL_DRIVER || driverName == MSSQL_NATIVE_DRIVER)
            {
                dsn.Driver = (driverName == MSSQL_DRIVER) ? "MsSql" : "MsSqlNative";
                dsn.DatabaseServer = (string)keyDsn.GetValue("Server");
                dsn.DatabaseName = (string)keyDsn.GetValue("Database");
                dsn.DatabaseUser = (string)keyDsn.GetValue("LastUser");
            }
            else if (driverName.ToLower().StartsWith(MYSQL_DRIVER.ToLower()))
            {
                dsn.Driver = "MySql";
                dsn.DatabaseServer = (string)keyDsn.GetValue("SERVER");
                dsn.DatabaseName = (string)keyDsn.GetValue("DATABASE");
                dsn.DatabaseUser = (string)keyDsn.GetValue("UID");
                dsn.DatabasePassword = (string)keyDsn.GetValue("PWD");
            }
            else if (driverName == MSACCESS_DRIVER)
            {
                dsn.Driver = "MsAccess";
                dsn.DatabaseName = (string)keyDsn.GetValue("DBQ");
                dsn.DatabaseUser = (string)keyDsn.GetValue("UID");
                dsn.DatabasePassword = (string)keyDsn.GetValue("PWD");
            }
            else if (driverName == MSEXCEL_DRIVER)
            {
                dsn.Driver = "Excel";
                dsn.DatabaseName = (string)keyDsn.GetValue("DBQ");
            }
            else if (driverName == TEXT_DRIVER)
            {
                dsn.Driver = "Text";
                dsn.DatabaseName = (string)keyDsn.GetValue("DefaultDir");
            }

            return dsn;
        }
 public int AddOdbcSource(SystemDSN item)
 {
     return OperatingSystemController.AddOdbcSource(item);
 }
 public int UpdateOdbcSource(SystemDSN item)
 {
     return OperatingSystemController.UpdateOdbcSource(item);
 }
        public static int AddOdbcSource(SystemDSN item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // check package
            int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive);
            if (packageCheck < 0) return packageCheck;

            // check quota
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.OS_ODBC);
            if (quota.QuotaExhausted)
                return BusinessErrorCodes.ERROR_OS_DSN_RESOURCE_QUOTA_LIMIT;

            // check if mail resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Os);
            if (serviceId == 0)
                return BusinessErrorCodes.ERROR_OS_RESOURCE_UNAVAILABLE;

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SystemDSN)) != null)
                return BusinessErrorCodes.ERROR_OS_DSN_PACKAGE_ITEM_EXISTS;

            // place log record
            TaskManager.StartTask("ODBC_DSN", "ADD", item.Name);

            try
            {
                // check service items
                OS.OperatingSystem os = GetOS(serviceId);
                if (os.GetDSN(item.Name) != null)
                    return BusinessErrorCodes.ERROR_OS_DSN_SERVICE_ITEM_EXISTS;

                string[] dbNameParts = item.DatabaseName.Split('|');
                string groupName = null;
                if (dbNameParts.Length > 1)
                {
                    item.DatabaseName = dbNameParts[0];
                    groupName = dbNameParts[1];
                }

                // get database server address
                item.DatabaseServer = GetDatabaseServerName(groupName, item.PackageId);

                if (item.Driver == "MsAccess" || item.Driver == "Excel" || item.Driver == "Text")
                    item.DatabaseName = FilesController.GetFullPackagePath(item.PackageId, item.DatabaseName);

                // add service item
                os.CreateDSN(item);

                // save item
                item.DatabasePassword = CryptoUtils.Encrypt(item.DatabasePassword);
                item.ServiceId = serviceId;
                int itemId = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;

                return itemId;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Пример #32
0
 public void UpdateDSN(SystemDSN dsn)
 {
     try
     {
         Log.WriteStart("'{0}' UpdateDSN", ProviderSettings.ProviderName);
         OsProvider.UpdateDSN(dsn);
         Log.WriteEnd("'{0}' UpdateDSN", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' UpdateDSN", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
        public void ImportItem(int packageId, int itemTypeId, Type itemType,
			ResourceGroupInfo group, string itemName)
        {
            // get service id
            int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName);
            if (serviceId == 0)
                return;

            if (itemType == typeof(SystemDSN))
            {
                // save DSN info
                SystemDSN dsn = new SystemDSN();
                dsn.Name = itemName;
                dsn.ServiceId = serviceId;
                dsn.PackageId = packageId;
                PackageController.AddPackageItem(dsn);
            }
        }
Пример #34
0
 /// <remarks/>
 public void CreateDSNAsync(SystemDSN dsn) {
     this.CreateDSNAsync(dsn, null);
 }