Showing posts with label SharePoint 2010 Database. Show all posts
Showing posts with label SharePoint 2010 Database. Show all posts

Wednesday, October 24, 2012

Tips to get accurate list of user created documents exclude system ones from SharePoint database



There are some use cases and scenarios where you need to retrieve SharePoint site collection information quickly without performance suffer through object model that will iterate all sub-sites and lists. One of the use cases is to evaluate third party search crawling index process accuracy on the site collection. We would like to get the accurate list of all documents exclude system ones in a site collection to compare the crawling result. The key here is to exclude system documents.

There are many different ways including using server object model, client object model, PowerShell, search API, SOAP/REST web service, or 3rd party tools. Another way, and a really quick one, is querying directly the SP content db tables or views. Since reading from a SharePoint DB (with the exception of the logging database) might leave it in an unsupported state indicated in KB article, I would suggest doing this in non-production environment. You could also confirm the script with Microsoft before run on production.

If you read the SP content db schema, you might find several SQL scripts to get list of documents from SharePoint database. Some of them are from SP 2007 that will no longer work and some of them will list many system files/documents. I modified the SQL script and added several enhancements so we could get accurate list of user created documents exclude system ones from SharePoint database without blocking other queries. Here are some tips.

  1. Use Docs view instead of AllDocs table to simplify query
  2. Join Docs view with UserData view to exclude system files/documents 
  3. All (NOLOCK) hint to both Docs and UserData views to prevent performance degradation
  4. Filter out file type to exclude system like files. Example is LeafName LIKE '%.stp' to exclude solution files
  5. Filter out directory type to exclude system like files. Example is filesDirName LIKE '%_catalogs%' as branding files
 Here is the script and you might need to exclude more additional system like files/documents.

SELECT

distinct DirName AS Directory,

UserData.nvarchar7 AS Title,

LeafName AS DocName,

Docs.Size AS Size,

Docs.TimeCreated AS Time

FROM Docs AS Docs WITH (NOLOCK) INNER JOIN UserData(NOLOCK) as UserData ON (Docs.DoclibRowId = UserData.tp_ID) AND Docs.ListId = UserData.tp_ListId

WHERE (DoclibRowId > 0)

AND Docs.ListID = UserData.tp_ListID
AND Docs.DoclibRowId = UserData.tp_ID
AND Docs.Type <> 1
AND (LeafName NOT LIKE '%.stp') 
AND (LeafName NOT LIKE '%.aspx')
AND (LeafName NOT LIKE '%.xfp')
AND (LeafName NOT LIKE '%.dwp')
AND (LeafName NOT LIKE '%template%')
AND (LeafName NOT LIKE '%.inf')
AND (LeafName NOT LIKE '%.css')
AND (LeafName NOT LIKE '%.master')
AND (LeafName NOT LIKE '%.xml')
AND (Docs.Size > 1)
AND (DirName NOT LIKE '%_catalogs%')
AND (DirName NOT LIKE 'personal%')
AND (DirName NOT LIKE '%Style%')
AND (DirName NOT LIKE '%SiteCollectionImages')
AND (DirName NOT LIKE 'mysites%')
AND (DirName NOT LIKE '%Publishing%')
AND (DirName NOT LIKE '%OntolicaStyles%')
AND (DirName NOT LIKE '%Data Connections for PerformancePoint%')
AND (DirName NOT LIKE '%ProjectBICenter/Templates%')
AND (DirName NOT LIKE '%Data Connections%')
AND (DirName NOT LIKE '%Reporting Templates%')
AND (DirName NOT LIKE '%FormServerTemplates%')
AND (DirName NOT LIKE '%ProjectBICenter/Sample Reports%')
AND (DirName NOT LIKE '%Pages%')

ORDER BY Directory


There are some other useful SQL query on users on the site collection and list data you could play around. Please remember to use these on non-production environment and consultant with Microsoft support before execute on production.

Wednesday, April 18, 2012

How to debug and resolve CanUpgrade [SPConfigurationDatabase] failed issue

We have run into the following error several times and it’s a good time to record the solution.

In one of DEV SharePoint development box today, when we deploy solution and the solution was stay in deploying status. We also received timer job error and we are not able to deploy any solution. The log shows the following error.

04/18/2012 12:50:05.63 OWSTIMER.EXE (0x0494)                              0x27BC SharePoint Foundation                 Upgrade                                       fbv7       Unexpected       [OWSTIMER] [SPUpgradeSession] [ERROR] 
[4/18/2012 12:50:05 PM]: CanUpgrade [SPConfigurationDatabase] failed.          
04/18/2012 12:50:05.63 OWSTIMER.EXE (0x0494)                              0x27BC SharePoint Foundation                 Upgrade                                       fbv7       Unexpected       [OWSTIMER] [SPUpgradeSession] [ERROR] 
[4/18/2012 12:50:05 PM]: Inner Exception: The type initializer for 'System.Data.SqlClient.SqlConnectionFactory' threw an exception.    
04/18/2012 12:50:05.63 OWSTIMER.EXE (0x0494)                              0x27BC SharePoint Foundation                 Upgrade                                       fbv7       Unexpected       [OWSTIMER] [SPUpgradeSession] [ERROR] 
[4/18/2012 12:50:05 PM]:    at System.Data.SqlClient.SqlConnection..cctor()    
04/18/2012 12:50:05.63 OWSTIMER.EXE (0x0494)                              0x27BC SharePoint Foundation                 Upgrade                                       fbv7       Unexpected       [OWSTIMER] [SPUpgradeSession] [ERROR] 
[4/18/2012 12:50:05 PM]: Exception: The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.              
… <Some error skipped here>
04/18/2012 12:50:05.63 OWSTIMER.EXE (0x0494)                              0x27BC SharePoint Foundation                 Timer                                         7v43       Medium               An error occured while initializing the timer.       
04/18/2012 12:50:05.63 OWSTIMER.EXE (0x0494)                              0x27BC SharePoint Foundation                 Timer                                         5utx       Unexpected       The timer service could not initialize its configuration, please check the configuration database.  Will retry later.

The error seems to indicate the upgrade and is very misleading. After debugging on the issue again, we realized this was the same issue we had before. The real error is in the application event log the DB is FULL. Here are two errors from SharePoint application event logs.



Now, it’s very clear that database is exceeding the limit. You could go to the location (our case is E:\SQL\Data) to review which DB is causing this issue. It’s as always the user profile sync application as in the following screen shot.


The solution is to shrink the DB and you will resolve the issue.

Monday, March 28, 2011

SharePoint 2010 content database dead lock after opening excel file with thousands of hyperlinks

We encountered a SharePoint database dead lock last week and this seems to be a bug on SharePoint database side. Here is the information that we found about this dead lock.

  1. Symptom of the issue -  After user opened an excel file or view the property of the file, the whole content database locked and users could not access anything inside this database on SharePoint 2010.
  2. Root cause - After looking closely on the actions that are causing this database dead lock, we identify there is a Microsoft excel file contains over 40,000 entries that are hyperlinks to other system. This could be just http://www.google.com. When users open the file or view the property of the file, this will cause the whole content database locked. When we track the issue, we isolate the call to the SQL server listed below is the root cause that triggers the dead lock.    

<?query --
SELECT DISTINCT
        Links.TargetDirName AS LinkDirName,
        Links.TargetLeafName AS LinkLeafName, Links.Type AS LinkType,
        Links.Security AS LinkSecurity, Links.Dynamic AS LinkDynamic,
        Links.ServerRel AS LinkServerRel, Docs.Type AS LinkStatus,
        PointsToDir AS PointsToDir, NULL AS WebPartId, NULL AS LinkNumber,
        NULL AS WebId, NULL AS Search, NULL AS FieldId
    FROM
        TVF_Links_PId_DId_Lvl(@DocSiteId, @DocParentId, @DocId, @Level) AS Links
    LEFT OUTER JOIN
        AllDocs AS Docs WITH (INDEX=AllDocs_Url)
    ON
        Links.ServerRel = 1 AND
        Docs.SiteId = Links.SiteId AND
        Docs.DeleteTransactionId = 0x AND   
        Docs.DirName = Links.TargetDirName AND
        Docs.LeafName = Links.TargetLeafName
    UNION ALL
    SELECT DISTINCT
        Docs.DirName AS LinkDirName,
        Docs.LeafName AS LinkLeafName, Links.Type AS LinkType,
        NULL AS LinkSecurity, NULL AS LinkDynamic, NULL AS LinkServerRel,
        CAST(128 AS tinyint) AS LinkStatus,
        NULL AS PointsToDir, NULL AS WebPartId,
        NULL AS LinkNumber, NULL AS WebId, NULL AS Search, NULL AS FieldId
    FROM
        TVF_Links_TargetUrlNotPointsToDir(@DocSiteId, @DocDirName, @DocLeafName) AS Links
    CROSS APPLY
        TVF_Docs_CI(Links.SiteId, Links.ParentId, Links.DocId, Links.Level) AS Docs
    UNION ALL
    SELECT DISTINCT
        Docs.DirName AS LinkDirName,
        Docs.LeafName AS LinkLeafName, Links.Type AS LinkType,
        NULL AS LinkSecurity, NULL AS LinkDynamic, NULL AS LinkServerRel,
        CAST(128 AS tinyint) AS LinkStatus,
        NULL AS PointsToDir, NULL AS WebPartId,
        NULL AS LinkNumber, NULL AS WebId, NULL AS Search, NULL AS FieldId
    FROM
        TVF_Links_TargetUrlPointsToDir(@DocSiteId, @DocDirName, @DocLeafName) AS Links
    CROSS APPLY
        TVF_Docs_CI(Links.SiteId, Links.ParentId, Links.DocId, Links.Level) AS Docs
    OPTION (FORCE ORDER, LOOP JOIN, MAXDOP 1)

--?>
  

     This query is coming from SharePoint OOB stored procedure “proc_GetLinkInfoSingleDocInternal” which is called from “proc_FetchDocForRead”. This stored procedure is invoked to request the
metadata information and document stream of a document. We are still working with Microsoft to identify the solution and submit a potential bug fix.

    3. Workaround - After we identify this issue is caused by the so many links of the excel file, we were able to remove the links inside the file and upload the file to SharePoint again. This seems to resolve the issue at this time. However, we lost the links inside the file. We did not test the threshold of number of links inside one file that would cause SQL content database dead lock.

With new SharePoint 2010 BI capabilities, more SharePoint users are using BI tool such as excel services. We would expect the much larger excel files with more links inside. Before Microsoft resolves this issue, please be careful the number of links inside a single excel file.