Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am working on C# utility(.exe) which will get SQL Server details.
A "VM2" is my SQL Server and utility will be run on it. Now utility will check is there any config db exists on "VM2".
if yes then get details like name, ID etc..

A point where i stuck is, i can get database details of all databases on sql server but wont identify SharePoint Config DB or SharePoint databases.

1] I tried as below :

C#
using (con = new SqlConnection("Data Source=" + txtServerName.Text + "; Integrated Security=True;"))
{
  con.Open();
  DataTable databases = con.GetSchema("Databases");
  List<ServerDatabseDetails> svrDBDetails = new List<ServerDatabseDetails>();
  ServerDatabseDetails svrDBDetail;

       foreach (DataRow database in databases.Rows)
         {
           svrDBDetail = new ServerDatabseDetails();
           svrDBDetail.DBName = database.Field<String>("database_name");
           svrDBDetail.DBID = database.Field<short>("dbid");
           svrDBDetail.CreationDate = database.Field<DateTime>("create_date");

           svrDBDetails.Add(svrDBDetail);
          }
   con.Close();
}

// Out come :- All database name and ID. Required only share point database details.


2] I tried with Powershell as below :

Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table Name
Out come :- It required sharepoint snapin, which wont be available on SQL Server. Because Microsoft.Sharepoint.dll is available on Application/WFE Server.


Note :- Suggestion with C#/Powershell will be appreciated.


Thanks in Advance :) !!!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900