I'm writing web service which will be part of my sharepoint solution. This service will save and read some data from custom db which will reside on the same mssql instance as sharepoint. I'd like my service to be reusable, so I'm looking for a way to get mssql instance name from sharepoint and use this to connect to DB. Have You ever done something like this before? Or maybe there is a better approach?

link|improve this question

60% accept rate
feedback

2 Answers

up vote 2 down vote accepted

In your web service, you can start beginning with "using" the SharePoint object model,

using Microsoft.SharePoint;

And then, get the Database instance properties using the SPDatabaseServiceInstance object.

Sample code might look like this

SPSite siteCollection = SPContext.Current.Site;
SPContentDatabase contentDB = siteCollection.ContentDatabase;
SPDatabaseServiceInstance contentDBInstance = contentDB.ServiceInstance;
link|improve this answer
feedback

There is a chance that service will not have access to SPContext and using SPFarm.Local will make more sense. You could use solution proposed in how to find the sqlserver name(data source) used by sharepoint?.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.