Skip to main content

Posts

Showing posts from July, 2009

Deleting SPListItem using Web Service

I was working on adding/deleting list items using web services. When we have to delete the SPListItem from a document library/list, it is mandatory to mention ID of that SPListItem. Ex., I cannot do something like this: This way of coding would have helped more: First, I would like to delete all the list items where City="Bengaluru". Second, many a times we do not expose ID column for the user. So, we would be interested only in those columns which matters. As a workaround, I had to use GetListItems to get the SPListItems where City = "Bengaluru" and then for each ID, execute UpdateListItems to delete those SPListItems.

GetDataTable() returns null

This actually bugged me for sometime! Look at this code: SPListItemCollection results = list.GetItems (myQuery); DataTable dtResults = results.GetDataTable(); Here, I'll execute a CAML (SPQuery) query against a list. From the SPListItemCollection, I'll try to get a DataTable. If the SPListItemCollection is empty (i.e., results.Count = 0), the second line assigns null to dtResults. So, if you are referring to dtResults in the following lines, application throws NullReferenceException ("Object reference not set to an instance of an object"). I was expecting that, if there is no list item, the data table should be kind of empty table (no row but it should have schema). So the summary is, whenever you are using GetDataTable(), make sure that you handle the null appropriately.

SharePoint Content Db in Suspect mode

While I was accessing my SharePoint site, suddenly, it threw the following error: A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) A few times, I also got the following error: Cannot open database "MyDb" requested by the login. The login failed. Login failed for user 'Domain\Username'. I opened SQL Server Management Studio and got to know that the Content Data