This code worked in our WCF service with SP 2007. In our new server on SP2010 this doesn't work. I do not know if the code needs to change or if there's something different about the configuration
Is this code wrong? Are there other configuration things I need to do? Search service is started.
StringBuilder queryText = new StringBuilder();
queryText.Append("SELECT PreferredName ");
queryText.Append("FROM SCOPE() ");
queryText.Append("WHERE \"scope\" = 'People' ");
Microsoft.Office.Server.Search.Query.FullTextSqlQuery query = new Microsoft.Office.Server.Search.Query.FullTextSqlQuery(SPContext.Current.Site);
query.QueryText = queryText.ToString();
query.ResultTypes = Microsoft.Office.Server.Search.Query.ResultType.RelevantResults;
query.RowLimit = 50;
Microsoft.Office.Server.Search.Query.ResultTableCollection results = query.Execute();
if ((int)ResultType.RelevantResults != 0 && results.Exists(ResultType.RelevantResults))
{
ResultTable tblResult = results[ResultType.RelevantResults];
DataTable relResultsTbl = new DataTable();
relResultsTbl.TableName = "Relevant Results";
DataSet ds = new DataSet("resultsset");
ds.Tables.Add(relResultsTbl);
ds.Load(tblResult, LoadOption.OverwriteChanges, relResultsTbl);
foreach (DataRow dataRow in ds.Tables[0].Rows)
{
accountNamesFromSearch.Add(dataRow["AccountName"] as string);
}
}
Quickly See if you can get the desired result in this MOSS Search tool good way to debug these kind of cases, rather than breaking our heads.
Related
net.What I am trying to do is to execute an MDX query using ado.net in Visual studio 2015.Can somebody please refer me the link so that I would able to know how it works.
Apart from that, I need to ask apart from the community that is ado.net is the only way to execute MDX queries can't I do it using something else.I am using vb.net as a server side language.Please let me know any link or code which would help me.
There is a lot information in internet, like this or that.
C#:
using (AdomdConnection conn = new AdomdConnection("Data Source=tfsDB;Initial Catalog=Tfs_Analysis; MDX Compatibility=1;"))
{
conn.Open();
var mdxQuery = new StringBuilder();
mdxQuery.Append("WITH ");
mdxQuery.Append("SET [Last 4 weeks] as Filter([Date].[Date].[Date], [Date].[Date].CurrentMember.Member_Value < Now() AND [Date].[Date].CurrentMember.Member_Value >= DateAdd(\"d\", - 28, Now())) ");
mdxQuery.Append("SELECT NON EMPTY Hierarchize(AddCalculatedMembers({DrilldownLevel({[Work Item].[System_WorkItemType].[All]})})) DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS , NON EMPTY {Hierarchize(Distinct({[Last 4 weeks]}))} DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON ROWS ");
mdxQuery.Append("FROM (SELECT ({[Work Item].[System_WorkItemType].&[Requirement], [Work Item].[System_WorkItemType].&[Change Request]}) ");
mdxQuery.Append("ON COLUMNS FROM [Team System]) WHERE ([Work Item].[Iteration Hierarchy].[All],[Test Case].[System_WorkItemType].[All],[Work Item].[System_State].&[Active],[Measures].[Work Item Count]) ");
using (AdomdCommand cmd = new AdomdCommand(mdxQuery.ToString(), conn))
{
DataSet ds = new DataSet();
ds.EnforceConstraints = false;
ds.Tables.Add();
DataTable dt = ds.Tables[0];
dt.Load(cmd.ExecuteReader());
return dt;
}
}
Since I prefer to use Linux on server side, you may check my blog post about accessing cubes via Python.
Python:
>>> import olap.xmla.xmla as xmla
No handlers could be found for logger "olap.xmla.requests_kerberosauth"
>>> provider = xmla.XMLAProvider()
>>> connect = provider.connect(location='http://localhost/OLAP/msmdpump.dll',username='test_user',password='1234567')
>>> source = connect.getOLAPSource()
>>> print source.getCatalog("TestCube")
XMLACatalog:(row){
CATALOG_NAME = "TestCube"
DESCRIPTION = ""
DATE_MODIFIED = "2016-08-07T09:47:05.026667"
}
I'm trying to get similar Document of another one . I'm using the Lucene.Net MoreLikeThis-Class to achieve this. For this i seperate my Documents in multiple Fields - Title and Content. Now creating the actual query results in an empty query without interesting Terms.
My could looks like this:
var queries = new List<Query>();
foreach(var docField in docFields)
var similarSearch = new MoreLikeThis(indexReader);
similarSearch.SetFieldNames(docField.fieldName);
similarSearch.Analyzer = new GermanAnalyzer(Version.LUCENE_30, new HashSet<string>(StopWords));
similarSearch.MinDocFreq = 1;
similarSearch.MinTermFreq = 1;
similarSearch.MinWordLen = 1;
similarSearch.Boost = true;
similarSearch.BoostFactor = boostFactor;
using(var reader = new StringReader(docField.Content)){
var searchQuery = similarSearch.Like(reader);
// debugging purpose
var queryString = searchQuery.ToString(); // empty
var terms = similarSearch.RetrieveInterestingTerms(reader); // also empty
queries.Add(searchQuery);
}
var booleanQuery = new BooleanQuery();
foreach(var moreLikeThisQuery in queries)
{
booleanQuery.Add(moreLikeThisQuery, Occur.SHOULD);
}
var topDocs = indexSearcher.Search(booleanQuery, maxNumberOfResults); // and of course no results obtained
So the question is:
Why there are no Terms / why there is no query generated?
I hope important thing's be seen, if not please help me to make my first question better :)
I got it to work.
The problem was, that i worked on the false directory.
I have different Solutions for creating the index and creating the queries and had a missmatch with the index-location.
So the generall solution would be:
Is your Querygenerating-Class fully initialized? (MinDocFreq, MinTermFreq, MinWordLen, has a Analyzer, set the fieldNames)
Is your used IndexReader correctly initialized?
I'm new in Excel development and I have an issue that It's driving me crazy. I hope you can help me.
Let me explain the situation,
I'm trying to create a QueryTable to import data from SQL , but ... I get an error at the moment to refresh the QueryTable,
the error message indicates that I'm not passing values for required parameters. ( It works hard coded :[ )
After many hours of investigation, I wasn't able to find a solution or an example to guide me... And here I am :|
I don't know what I'm doing wrong, Here is some code
foreach (Range row in main.Rows)
{
//row.Clear();
rowID = row.Row;
if (string.IsNullOrEmpty(getAccounts(rowID, columnID)) )
continue;
/* string connectionString = // \"
string.Format("OLEDB;Provider=SQLOLEDB;Data Source={0};Initial Catalog={1};User ID={2};Password={3}",
*/
//string sql = "EXECUTE [Funciones].[Cuenta_Saldo_Anho] ?,?";
//if (!string.IsNullOrEmpty(txtTipoSaldo.Text)) sql += ",?";
string sql = "{CALL [Funciones].[Cuenta_Saldo_Anho] (?, ?";
sql += (!string.IsNullOrEmpty(txtTipoSaldo.Text))? "" : ", ?" + ")}"; // optional parameter
var qt = wSheet.QueryTables.Add( connectionString, row.Cells , sql);
qt.CommandType = XlCmdType.xlCmdSql;
var ctas = qt.Parameters.Add("#ctas", XlParameterDataType.xlParamTypeLongVarChar);
//ctas.SetParam(XlParameterType.xlConstant, cuentas);
ctas.SetParam(XlParameterType.xlRange, wSheet.Cells[rowID, columnID]));
ctas.RefreshOnChange = true;
qt.Parameters.Add("#anho", XlParameterDataType.xlParamTypeInteger)
.SetParam(XlParameterType.xlConstant, Int32.Parse(anho));
qt.Parameters.Add("#tipoSaldo", XlParameterDataType.xlParamTypeVarChar)
.SetParam(XlParameterType.xlConstant, txtTipoSaldo.Text);
//qt.BackgroundQuery = true;
qt.FieldNames = false;
qt.AdjustColumnWidth = false;
qt.RefreshOnFileOpen = false;
qt.Refresh();
}
Any help is welcome. Thanks.
I have a few tables in a c# application I'm currently working on and for 4/5 of the tables everything saves perfectly fine no issues. For the 5th table everything seems good until I reload the program again (without modifying the code or working with a seperate install so that the data doesn't go away) The 4/5 tables are fine but the 5th doesn't have any records in it after it has been restarted (but it did the last time it was running). Below is some code excerpts. I have tried a few different solutions online including creating a string to run the sql commands on the database manually and creating the row directly as opposed to the below implementation which uses a generic data row.
//From main window
private void newInvoice_Click(object sender, EventArgs e)
{
PosDatabaseDataSet.InvoicesRow newInvoice = posDatabaseDataSet1.Invoices.NewInvoicesRow();
Invoices iForm = new Invoices(newInvoice, posDatabaseDataSet1, true);
}
//Invoices Table save [Works] (from Invoices.cs)
private void saveInvoice_Click(object sender, EventArgs e)
{
iRecord.Date = Convert.ToDateTime(this.dateField.Text);
iRecord.InvoiceNo = Convert.ToInt32(this.invoiceNumField.Text);
iRecord.Subtotal = (float) Convert.ToDouble(this.subtotalField.Text);
iRecord.Tax1 = (float)Convert.ToDouble(this.hstField.Text);
iRecord.Total = (float)Convert.ToDouble(this.totalField.Text);
iRecord.BillTo = this.billToField.Text;
invoicesBindingSource.EndEdit();
if (newRecord)
{
dSet.Invoices.Rows.Add(iRecord);
invoicesTableAdapter.Adapter.Update(dSet.Invoices);
}
else
{
string connString = Properties.Settings.Default.PosDatabaseConnectionString;
string queryString = "UPDATE dbo.Invoices set ";
queryString += "Date='" + iRecord.Date+"'";
queryString += ", Subtotal=" + iRecord.Subtotal;
queryString += ", Tax1=" + iRecord.Tax1.ToString("N2");
queryString += ", Total=" + iRecord.Total;
queryString += " WHERE InvoiceNo=" + iRecord.InvoiceNo;
using (SqlConnection dbConn = new SqlConnection(connString))
{
SqlCommand command = new SqlCommand(queryString, dbConn);
dbConn.Open();
SqlDataReader r = command.ExecuteReader();
dbConn.Close();
}
}
dSet.Invoices.AcceptChanges();
}
//Invoice Items save [works until restart] (also from Invoices.cs)
private void addLine_Click(object sender, EventArgs e)
{
DataRow iRow = dSet.Tables["InvoiceItems"].NewRow();
iRow["Cost"] = (float)Convert.ToDouble(this.costField.Text);
iRow["Description"] = this.descriptionField.Text;
iRow["InvoiceNo"] = Convert.ToInt32(this.invoiceNumField.Text);
iRow["JobId"] = Convert.ToInt32(this.jobIdField.Text);
iRow["Qty"] = Convert.ToInt32(this.quantityField.Text);
iRow["SalesPerson"] = Convert.ToInt32(this.salesPersonField.Text);
iRow["SKU"] = Convert.ToInt32(this.skuField.Text);
dSet.Tables["InvoiceItems"].Rows.Add(iRow);
invoiceItemsTableAdapter.Adapter.Update(dSet,"InvoiceItems");
PosDatabaseDataSet.InvoiceItemsDataTable dTable = (PosDatabaseDataSet.InvoiceItemsDataTable)dSet.InvoiceItems.Copy();
DataRow[] d = dTable.Select("InvoiceNo=" + invNo.ToString());
invoiceItemsView.DataSource = d;
}
Thanks in advance for any insight.
UPDATE: October 17, 2011. I am still unable to get this working is there any more ideas out there?
you must execute your Sql Command in order to persis the changes you made.
using (SqlConnection dbConn = new SqlConnection(connString))
{
dbConn.Open();
SqlCommand command = new SqlCommand(queryString, dbConn);
command.ExecuteNonQuery();
dbConn.Close();
}
The ExecuteReader method is intended (as the name says) to read the data from a SQL table. You need to use a different method as you can see above.
We need some more info first, you haven't shown the case where your code fails.
Common mistakes on this kind of code is calling DataSet.AcceptChanges() before actually committing the changes to the database.
Second is a conflict between databound data through the binding source vs edits to the dataset directly.
Lets see the appropriate code and we can try and help.
Set a breakpoint after teh call to invoiceItemsTableAdapter and check the InvoiceItems table for the row you have added. Release the breakpoint and then close your app. Check the database again. I would say that another table may be forcibly overwriting the invoice item table.
I have a button which saves the contents edited in datagridview in my UI design. Here is the code for that Button_Save:
public void btnUpdate_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection("server=Test; Integrated Security=true; Database=Test;");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
var sql = new StringBuilder();
sql.AppendLine("UPDATE dbo.JobStatus");
sql.AppendLine("Set ShipTrackingNumber = #ShipTrackingNumber");
sql.AppendLine(", ShipMethodTransmitted = #ShipMethodTransmitted");
sql.AppendLine(", DateShipTransmitProcessed = #DateShipTransmitProcessed");
sql.AppendLine(", ShipmentProcessedBy = #ShipmentProcessedBy");
sql.AppendLine(", Critical = #Critical");
sql.AppendLine(", ShipTransmitStatus = #ShipTransmitStatus");
sql.AppendLine("Where jobtableId = #jobTableId");
cmd.Connection = sqlConnection1;
cmd.CommandText = sql.ToString();
cmd.Parameters.AddWithValue("#TrackingNumber", row.Cells[7].FormattedValue);
cmd.Parameters.AddWithValue("#ShipMethodTransmitted", row.Cells[8].FormattedValue);
cmd.Parameters.AddWithValue("#DateShipTransmitProcessed", row.Cells[9].FormattedValue);
cmd.Parameters.AddWithValue("#ShipmentProcessedBy", row.Cells[10].FormattedValue);
cmd.Parameters.AddWithValue("#Critical", row.Cells[11].FormattedValue);
cmd.Parameters.AddWithValue("#ShipTransmitStatus", row.Cells[13].FormattedValue);
cmd.Parameters.AddWithValue("#jobTableId", row.Cells[5].FormattedValue);
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
What I am getting error is that: "Must declare the scalar variable "#ShipTrackingNumber".
I dont want to put ShipTrackingNumber from the code. Instead I want to fetch it from the UI.
What I am doing wrong here?
Well, there's no entry in cmd.Parameters for "#ShipTrackingNumber". What do you mean by "fetch it from the UI"? You could just write a line to add an entry for this parameter:
cmd.Parameters.AddWithValue("#ShipTrackingNumber", GetShipTrackingNumberFromUI());
And then implement GetShipTrackingNumberFromUI() to get the value you want.
It looks like this line is supposed to be something along these lines, but you need to change "#TrackingNumber" to "#ShipTrackingNumber":
cmd.Parameters.AddWithValue("#TrackingNumber", row.Cells[7].FormattedValue);
To answer your direct question, add the parameter with its value taken from the UI. Let's say it's a checkbox named CheckBox1:
cmd.Parameters.AddWithValue("#ShipTrackingNumber", CheckBox1.Checked);
You need to replace this line:
cmd.Parameters.AddWithValue("#TrackingNumber", row.Cells[7].FormattedValue);
with this line:
cmd.Parameters.AddWithValue("#ShipTrackingNumber", row.Cells[7].FormattedValue);