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:
Application Pool Identity is the farm account.
Farm Configurations:
- SharePoint 2019
- SQL Server 2017
Any help is much appreciated!