Here we will discuss how we can retrieve all content database name for web applications using SharePoint 2016 server object model. In my last post, we have discussed how to retrieve all web application names from SharePoint farm using server object model in SharePoint 2016.
Here I have shown in a windows application. I have SharePoint 2016 installed on the same machine, so I can add Microsoft.SharePoint.dll into the windows application and can write server-side code inside it.
You can see the SharePoint 2016 installation steps and SharePoint 2016 new and improved features.
Below is the full code to get the content database name:
string s = string.Empty;
SPFarm farm = SPFarm.Local;
SPWebService service = farm.Services.GetValue<SPWebService>(“”);
foreach (SPWebApplication webapp in service.WebApplications)
foreach (SPSite site in webapp.Sites)
s += “Site Collection URL: ” + site.Url + ” Content Database Name: ” + site.ContentDatabase.Name + “\n”;
label9.Text = s;
Once you run the code, it will display all site collection urls and corresponding content database names like below:
Hope this will be helpful.
Download FREE SharePoint 2019 Installation PDF Guide
This FREE PDF contains, Steps by step guide to install SharePoint 2019 Preview, prerequisites, hardware and software new features. First impression to SharePoint Server 2019 new modern site, modern lists and modern document libraries.
You May Also like the Following SharePoint Online Tutorials: