The search request was unable to connect to the Search Service - sharepoint

I am developing a sharepoint site using sharepoint object model. I am getting "The search request was unable to connect to the Search Service" message on execute FullTextSqlQuery. Office Sharepoint Server Search and Indexing Service are running. How can I solve this problem?
Here is code:
FullTextSqlQuery qry = new FullTextSqlQuery(SPContext.Current.Site);
qry.QueryText = "SELECT Path, Title, Rank, Description FROM portal..scope() Where FREETEXT(*,'\"" + keys + "\"') ORDER BY \"Path\" DESC";
qry.EnableStemming = true;
qry.ResultTypes = ResultType.RelevantResults;
qry.KeywordInclusion = KeywordInclusion.AllKeywords;
qry.AuthenticationType = QueryAuthenticationType.NtAuthenticatedQuery;
ResultTableCollection queryResults = qry.Execute();
ResultTable queryResultsTable = queryResults[ResultType.RelevantResults];
DataTable queryDataTable = new DataTable();
queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);
ResultTable queryResultsTable = queryResults[ResultType.RelevantResults];
DataTable queryDataTable = new DataTable();
queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);

See following:
http://urenjoy.blogspot.com/2009/02/error-search-request-was-unable-to.html

Related

Sharepoint 2016 on-premise details Item Version field informations

I am working on SharePoint 2016 CSOM to get list item version history. unfortunately i am not getting the field values. please find the code below.
var file = item.File;
var versionFiles = file.Versions;
var fa = file.ListItemAllFields;
clientContext.Load(fa);
clientContext.Load(file);
clientContext.Load(versionFiles);
clientContext.ExecuteQuery();
if (null != versionFiles)
{
var fileVersion = file.Versions[5];
SP.File oldFile =web.GetFileByServerRelativeUrl("/sites/site/_vti_history/1234/list1/file1.pdf");
var allField = oldFile.ListItemAllFields;
clientContext.Load(allField);
}
You could get version history metadata from Lists.asmx.
Sample code:
var web = clientContext.Web;
List spList = clientContext.Web.Lists.GetByTitle("MyDoc");
var item = spList.GetItemById(43);
clientContext.Load(spList);
clientContext.Load(item);
clientContext.ExecuteQuery();
#region customList
Lists.Lists listService = new Lists.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
listService.Url = siteUrl + "/_vti_bin/lists.asmx";
XmlNode nodeAttachments = listService.GetVersionCollection(spList.Id.ToString(), item.Id.ToString(), "Title");
foreach (System.Xml.XmlNode xNode in nodeAttachments)
{
Console.WriteLine(xNode.Attributes["Title"].Value);
}

New Calendar Event Does Not Display

I'm using C# and CSOM to build an application that creates an event in a SharePoint calendar that I know exists in my O365 subscription. I know O365 is SharePoint 2013, but my application targets SharePoint 2010, so I'm going to have to deal with both versions.
No exceptions are thrown and everything appears to succeed, but the new event does not display in the calendar, even after a page refresh. If I get a collection of items with the same event title, the program-entered event is returned, and appears to contain all the columns set in code.
The CalendarItemCreate function puts data in all the required columns of the calendar. If I search for other calendar items I have hand-entered through the SharePoint calendar, I find them. The only difference I can see between either hand-entered or program-entered events is the "Description" column has ' for the hand-entered events.
Any ideas?
private void CalendarItemCreate(ICalendarItem item) {
using (var context = new ClientContext(_calendarLocation)) {
context.Credentials = _credentials;
var web = context.Web;
var transferScheduleList = web.Lists.GetByTitle(TransferScheduleToken);
var listItemCreationInformation = new ListItemCreationInformation();
var listItem = transferScheduleList.AddItem(listItemCreationInformation);
listItem[TitleToken] = item.EventTitle;
listItem[EventDateToken] = item.EventStartLocal;
listItem[EndDateToken] = item.EventStartLocal.AddMinutes(30);
listItem[DescriptionToken] = string.Empty; //item.EventDescription;
listItem[TransferTypeToken] = item.EventTransferType;
listItem[TransferStatusToken] = item.EventTransferStatus;
listItem[CategoryToken] = "Data Transfer";
listItem[ConfigurationFileLocationToken] = item.ConfigurationFileLocation;
listItem[EventTypeToken] = 0;
listItem[FallDayEventToken] = false;
listItem[FrecurrenceToken] = false;
listItem.Update();
context.ExecuteQuery();
}
The solution was a combination of formatting the dates as strings that SharePoint could understand and data type mismatches in two of my transfer columns. The code below was successful.
using (var context = new ClientContext(_calendarLocation)) {
context.Credentials = _credentials;
var web = context.Web;
var transferScheduleList = web.Lists.GetByTitle(TransferScheduleToken);
var listItemCreationInformation = new ListItemCreationInformation();
var listItem = transferScheduleList.AddItem(listItemCreationInformation);
listItem[TitleToken] = item.EventTitle;
listItem[EventDateToken] = item.EventStartLocal.ToUniversalTime().ToString(#"yyyy-MM-ddTHH:mm:ssZ");
listItem[EndDateToken] = item.EventStartLocal.AddMinutes(30).ToUniversalTime().ToString(#"yyyy-MM-ddTHH:mm:ssZ");
listItem[DescriptionToken] = item.EventDescription;
listItem[TransferTypeToken] = item.EventTransferType.ToString();
listItem[TransferStatusToken] = item.EventTransferStatus.ToString();
listItem[CategoryToken] = "Data Transfer";
listItem[ConfigurationFileLocationToken] = item.ConfigurationFileLocation;
listItem[EventTypeToken] = 0;
listItem[FallDayEventToken] = false;
listItem[FrecurrenceToken] = false;
listItem.Update();
context.ExecuteQuery();

Filter a sharepoint visual web part through created by column through code

I created a visual web part and loading the list in Grid. Now when User A login it has to display only the items which are created by user A. USER B it has to display only the items that belong to USER b. Here is the code which i have written.It Display all the items irrespective of the logged in user. Can any one help me on this
public void Displaylistdata()
{
// System.Diagnostics.Debugger.Break();
DataTable dt = new DataTable();
var oSPWeb = SPContext.Current.Web;
SPList oSpList = oSPWeb.Lists["Participation at a Glance"];
string strCreatedby = SPContext.Current.Web.Author.Name;
SPQuery oQuery = new SPQuery();
oQuery.Query = "<Query><Where><Eq><FieldRef Name='Author' /><Value Type='User'>" + strCreatedby + "</Value></Eq></Where></Query>";
SPListItemCollection collListItems = oSpList.GetItems(oQuery);
DataTable dts = collListItems.GetDataTable();
if (dts != null)
{
Gridview1.GridLines = GridLines.None;
Gridview1.DataSource = dts;
Gridview1.DataBind();
Controls.Add(Gridview1);
}
else`enter code here`
{
lbl_noact.Visible = true;
lbl_noact.Text = "We apologize there are no times currently available.";
}
}
Hi I have fixed by changing my Camel query as below. Previously the data type is USER but when i changed to string it works like a charm :-)
DataTable dt = new DataTable();
var oSPWeb = SPContext.Current.Web;
SPList oSpList = oSPWeb.Lists["Participation at a Glance"];
string strCreatedby = SPContext.Current.Web.CurrentUser.Name;
SPQuery oQuery = new SPQuery();
oQuery.Query = #"<Where><Eq><FieldRef Name='Author' /><Value Type='String'>" + strCreatedby + "</Value></Eq></Where>";
SPListItemCollection collListItems = oSpList.GetItems(oQuery);

SharePoint 2010 - use SPS-Birthday in FullTextSqlQuery

I'm trying to build a custom webpart for displaying upcoming birthdays.
This code works but I need to retrieve the Birthday to filter my results.
I tried using SPS-Birthday but then I get an exception
public static void BirthDay()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
StringBuilder queryText = new StringBuilder();
queryText.Append("SELECT PreferredName, AccountName, ??SPS-BIRTHDAY??");
queryText.Append("FROM SCOPE() ");
queryText.Append("WHERE \"scope\" = 'People' ");
using (FullTextSqlQuery query = new FullTextSqlQuery(site))
{
query.QueryText = queryText.ToString();
query.RankingModelId = "D9BFB1A1-9036-4627-83B2-BBD9983AC8A1";
query.KeywordInclusion = KeywordInclusion.AnyKeyword;
query.ResultTypes = ResultType.RelevantResults;
query.RowLimit = 5000;
ResultTableCollection results = new ResultTableCollection();
try
{
results = query.Execute();
if (results.Count == 0)
throw new ArgumentException("// No results");
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex.InnerException);
}
ResultTable relevantResults = results[ResultType.RelevantResults];
resultDataTable = new DataTable();
resultDataTable.Load(relevantResults, LoadOption.OverwriteChanges);
count = resultDataTable.Rows.Count;
}
}
});
Try going into Central Admin and making sure that the Birthday field can be "Used in Scopes". Go to Central Admin->Manage Search Service application->Metadata Properties...then look for and select that Birthday property under Managed Properties...then click "Use this field in scopes"

SharePoint Search Error

I am trying to do a search on a scope in SharePoint. I see this
error.
My code:
using (SPSite siteCollection = new SPSite("http://sp:25000/"))
{
// create a new FullTextSqlQuery class - use property intializers to set query
FullTextSqlQuery query = new FullTextSqlQuery(siteCollection);
query.QueryText = "SELECT Title" + " from scope() where \"scope\" ='ArticleScope'" + "and Contentclass = 'STS_ListItem_GenericList'";
query.ResultTypes = ResultType.RelevantResults;
query.RowLimit = Int32.MaxValue;
query.TrimDuplicates = true;
query.EnableStemming = false;
query.IgnoreAllNoiseQuery = true;
query.KeywordInclusion = KeywordInclusion.AllKeywords;
query.Timeout = 0x2710;
query.HighlightedSentenceCount = 3;
query.SiteContext = new Uri(siteCollection.Url);
// execute the query and load the results into a datatable
ResultTableCollection queryResults = query.Execute();
ResultTable queryResultsTable = queryResults[ResultType.RelevantResults];
DataTable queryDataTable = new DataTable();
queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);
}
Fixed!!!
Used this link
The code I have used:
using (SPSite siteCollection = new SPSite("http://sp:25000/"))
{
Microsoft.Office.Server.Search.Query.FullTextSqlQuery query = new Microsoft.Office.Server.Search.Query.FullTextSqlQuery(siteCollection);
query.QueryText = "SELECT Title from scope() where \"scope\" ='All Sites' and Contentclass = 'STS_ListItem_GenericList'";
query.ResultTypes = Microsoft.Office.Server.Search.Query.ResultType.RelevantResults;
query.RowLimit = Int32.MaxValue;
query.TrimDuplicates = true;
query.EnableStemming = false;
query.IgnoreAllNoiseQuery = true;
query.KeywordInclusion = Microsoft.Office.Server.Search.Query.KeywordInclusion.AllKeywords;
query.Timeout = 0x2710;
query.HighlightedSentenceCount = 3;
query.SiteContext = new Uri(siteCollection.Url);
query.AuthenticationType = Microsoft.Office.Server.Search.Query.QueryAuthenticationType.NtAuthenticatedQuery;
Microsoft.Office.Server.Search.Query.ResultTableCollection queryResults = query.Execute();
Microsoft.Office.Server.Search.Query.ResultTable queryResultsTable = queryResults[Microsoft.Office.Server.Search.Query.ResultType.RelevantResults];
DataTable queryDataTable = new DataTable();
queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);
}
Thanks for your support.
How are you accessing SharePoint? From the screenshot it seems as if you have a Web Page running in a Non-SharePoint IIS Web Application on a SharePoint server, which is not supported (Referencing the Microsoft.SharePoint Assembly from ANY Application running outside SharePoint is officially unsupported, even though some features may run)
What happens if you run this code from within SharePoint (i.e. in a Web Part)?
I can't see the error as it's blocked by my proxy. However my guess is that you should have a space before the and. (Is there any reason why this isn't one long string?)
'ArticleScope'" + "and
^
If not can you please copy and paste the error into your question.
You are missing a space before the and.
THis means
where \"scope\" ='ArticleScope'" + "and Contentclass = 'STS_ListItem_GenericList'
becomes
where \"scope\" ='ArticleScope'and Contentclass = 'STS_ListItem_GenericList'
'ArticleScope' and AND are concatenated: 'ArticleScope'and
Are you using Microsoft SharePoint Server 2007 (MOSS)? Or do you only have Windows SharePoint Services 3.0 (WSS)? From what I saw, Scopes are a MOSS-Feature not available in WSS, but I'm guessing a bit.

Resources