Hi,
Can u people Help me How to get the sqlserver name used by sharepoint programatically?? is there any such api provided like i have installed sharepoint on the sqlnamed instance. How to get the sqlservername.
Thanks in Advance...
Hi,
Can u people Help me How to get the sqlserver name used by sharepoint programatically?? is there any such api provided like i have installed sharepoint on the sqlnamed instance. How to get the sqlservername.
Thanks in Advance...
This code should help you and you need to run this code from the SharePoint Server or WFE server.
public String GetSharePointSQLServerName()
{
String sServerName = "notFound";
foreach (var item in SPFarm.Local.Servers)
{
foreach (var svc in item.ServiceInstances)
{
if (svc is SPDatabaseServiceInstance)
{
SPDatabaseServiceInstance s = svc as SPDatabaseServiceInstance;
sServerName = item.DisplayName+"\\"+s.Instance;
}
}
}
return sServerName;
}