Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Error with SPQuery.Query method

  Asked By: Elvis    Date: Jul 19    Category: Sharepoint    Views: 2188

Anyone have experience with the SPQuery class? I am getting the following error on trying to use the GetItems(spQuery method).

Message: SQL Server Error. The SQL Server might not be started.

Source: Microsoft.SharePoint

Stack: at Microsoft.SharePoint.Library.a.a(String A_0, String A_1, String A_2, String A_3, Boolean A_4, Boolean A_5, Boolean A_6, UInt32& A_7, UInt32& A_8, Object& A_9, String& A_10)

at Microsoft.SharePoint.SPListItemCollection.a(Boolean A_0)

at Microsoft.SharePoint.SPListItemCollection..ctor(SPList A_0, SPQuery A_1, String A_2)

at Microsoft.SharePoint.SPListItemCollection..ctor(SPList A_0, SPQuery A_1)

at Microsoft.SharePoint.SPList.GetItems(SPQuery query)

at VacationRequestHandler.VacationRequestHandler.OnEvent(SPListEvent evSharepointEvent)

The following is my code sequence:

SPQuery query = new SPQuery();

query.Query = "<Where><Eq><FieldRef Name='Requested_x0020_By'/>" +

"<Value Type='Number'>" + userID + "</Value></Eq></Where>";

//The following line throws the error

SPListItemCollection myItems = list.GetItems(query);

However, SQL Server is obviously started, because I can access the list in its entirety by using list.items instead of list.GetItems(query).

Anyone have any suggestions? Is it a problem with how I formatted the query string?



1 Answer Found

Answer #1    Answered By: Rashawn Hopper     Answered On: Jul 19

A few things to try …

1) Try adding <Query></Query> around the string  you have … I have some code  that I wrote that I’m looking at that has this around basically the same text you have…

2) Change your single quotes to double quotes. \” is a double quote encoded … My code is using double quotes.

Didn't find what you were looking for? Find more on Error with SPQuery.Query method Or get search suggestion and latest updates.