Пример #1
0
    private void CreateDatabasePartition4Organization(Int32 currOrganizationCode, Int32 intOrganizationCode)
    {
        try
        {
            String           strOrganizationName = txtDomainName.Text.Trim().ToLower().Replace("http://", String.Empty);
            String           strOranizationCode  = MakeZeroString(intOrganizationCode);
            String           strDataFileName     = "datafile_" + strOranizationCode;
            String           strFileGroupName    = "filegrp_" + strOranizationCode;
            ServerConnection cnnServer           = new ServerConnection(System.Configuration.ConfigurationManager.AppSettings["DataCentreHost"], "sa", "q2c4b7m1");
            Server           myServer            = new Server(cnnServer);
            Database         LapbaseDatabase     = myServer.Databases[System.Configuration.ConfigurationManager.AppSettings["LapbaseDatabase"]];
            FileGroup        orgFileGroup;

            if (LapbaseDatabase.FileGroups.Contains(strFileGroupName))
            {
                orgFileGroup = LapbaseDatabase.FileGroups[strFileGroupName];
            }
            else
            {
                orgFileGroup = new FileGroup(LapbaseDatabase, strFileGroupName);
                orgFileGroup.Create();
            }

            try
            {
                DataFile orgDataFile = new DataFile(orgFileGroup, strDataFileName, LapbaseDatabase.PrimaryFilePath + @"\" + strDataFileName + ".ndf");
                orgDataFile.IsPrimaryFile = false;
                orgDataFile.Size          = 10240; //Initial size: 10 MB
                orgDataFile.Growth        = 10240; //Growth by : 10 MB
                orgDataFile.Create();
                PartitionScheme schemePartiton = LapbaseDatabase.PartitionSchemes["scheme_OrganizationCodePartition"];
                try { schemePartiton.NextUsedFileGroup = orgFileGroup.Name; schemePartiton.Alter(); }
                catch (Exception err) { gClass.AddErrorLogData("0", Request.Url.Host, "", "CreateDatabasePartition4Organization", "schemePartiton.NextUsedFileGroup", err.ToString()); }
                PartitionFunction fnPartition = LapbaseDatabase.PartitionFunctions["fn_OrganizationCodePartition"];
                try { fnPartition.SplitRangePartition(intOrganizationCode); fnPartition.Alter(); }
                catch (Exception err) { gClass.AddErrorLogData("0", Request.Url.Host, "", "CreateDatabasePartition4Organization", "fnPartition.SplitRangePartition", err.ToString()); }
            }
            catch (Exception err) { gClass.AddErrorLogData("0", Request.Url.Host, "", "CreateDatabasePartition4Organization", "Add new organization", err.ToString()); }


            LapbaseDatabase.Refresh();
            cnnServer.Disconnect();
        }
        catch (Exception ex) { gClass.AddErrorLogData("0", Request.Url.Host, "", "linkbtnSaveOrganization_onclick", "Add new organization", ex.ToString()); }
    }