I've did some research on Internet and found some code examples how to retrieve search scopes, but when I try to execute it fails, what do I do wrong?
Here is the code:
SPServiceContext serviceContext = SPServiceContext.GetContext(SPContext.Current.Site);
SearchServiceApplicationProxy searchServiceAppProxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;
SearchServiceApplicationInfo searchSerivceAppInfo = searchServiceAppProxy.GetSearchServiceApplicationInfo();
SearchServiceApplication searchServiceApplication = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(searchSerivceAppInfo.SearchServiceApplicationId);
Scopes scopes = new Scopes(searchServiceApplication);
foreach (Scope scope in scopes.GetSharedScopes())
{
scopeList.Add(scope);
}
Ok in this case I try to get SharedScopes but in general I just need to get all scopes, if i do scopes.AllScopes it doesnt work.
I checked the Log files and it seems I get an error there, some error that says, fail to connect to database and so on and so on. And it happens exactly on the like where i do scopes.AllScopes (or scopes.GetSharedScopes()) and so on). Do I miss something? I even tried to run this code with elevated privileges, but that doesn't help. Still the same error.
So what do I miss?
Update: I don't know, I suppose that that account has enought rights as it is systemaccount, here is the error:
Cannot open database "Search_Service_Application_DB_71f6d22eda5e4eecbc4e225360b2d5a6" requested by the login. The login failed. Login failed for user 'sp2010appweb'. at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)....