Domanda

I'm trying to create a new site collection using below code:

SPWebApplication webApp = new SPSite(webAppURL).WebApplication;
                    SPSiteCollection siteCollections = webApp.Sites;

                    if (!SPSite.Exists(new Uri(webAppURL + siteURL)))
                    {
                        var storeContext = HttpContext.Current;
                        HttpContext.Current = null;

                        SPSite newSiteCollection = siteCollections.Add(siteURL,
                        projectCode,
                        projectTitle,
                        CommonConstants.LCID,
                        CommonConstants.SiteTemplate,
                        primaryUserName,
                        string.Empty,
                        string.Empty,
                        secondaryUserName,
                        string.Empty,
                        string.Empty,
                        dbServer,
                        projectCode,
                        dbUserName,
                        dbPassword);

                        SPContentDatabase contentDatabase = newSiteCollection.ContentDatabase;
                        contentDatabase.MaximumSiteCount = 1;
                        contentDatabase.WarningSiteCount = 0;
                        contentDatabase.Update();

                        HttpContext.Current = storeContext;
                    return true;
                    }

If I run the Visual studio it is working fine. However, If I'm creating a build and hosting it in IIS, the content database is created successfully but cannot create site collection and throwing below error:

enter image description here

Application Pool Identity is the farm account.

Farm Configurations:

  • SharePoint 2019
  • SQL Server 2017

Any help is much appreciated!

È stato utile?

Soluzione

According to your source code you are creating a site collection then updating the related content database with a maximum site collection with one.

That piece of code might work only one time for one web application if before you are not creating a new content database or incrementing the MaximumSiteCount by 1.

So, before calling the SPSiteCollection.Add method, ensure that you have at least one content database available for a new one into your WebApplication otherwise you will have that kind of issue again.

In the past I had that requirement, one content database per site collection. The way was managing first the content database creation then creating the site collection inside by using the content database as main reference instead of the WebApplication.

SPContentDatabase.Sites.Add

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top