Sue Hernandez's SharePoint Blog

SharePoint and Related Stuff

What happened to my ULS Logs? Why is the Tracing service disabled?

I was happily developing and testing, and came across an error.  No big deal, I’ll just grab the Correlation ID and take a peek in the ULS logs, right?  But when I went to where they were stored – there were NO logs.

First I went to Central Admin –> Monitoring –> Configure Diagnostic logging.

  • I checked to ensure the path was correct
  • I reset all categories to default logging level
  • I even tried to change the log location, then change it back.

Nothing.

Then I noticed that in the “Services” mmc plugin, the service “SharePoint Tracing Service” (SPTraceV4) was not only stopped but disabled!

Well OK, so I enabled it and started it.   And got my logs just fine!!!  ………for about an hour, after which it just disabled itself again.  Sigh.

Found the answer on StackExchange (link below) – the “default state” of the service was set to Disabled, so the Health Analyzer keeps shutting it back off.  So the fix is to change its default state to back on.

$services = (Get-SPFarm).Services | Where Name -match "SPTraceV4"
$instances = @($services.Instances)

foreach($instance in $instances) {
     $id = $instance.ID | Select -ExpandProperty Guid

     Start-SPServiceInstance -Identity $id
}

References

https://sharepoint.stackexchange.com/questions/62897/sptracev4-being-disabled

~ Sue

Advertisements

Error occurred in deployment step ‘Add Solution’: Error: Cannot add the specified assembly to the global assembly cache

Hello Again!

It’s been a while!!  Things have been hectic.  I am now employed at a new job, doing more SharePoint-ie things!!  And thankfully, learning, learning, learning!!

Error Message:

Came across this error today:
“Error occurred in deployment step ‘Add Solution’: Error: Cannot add the specified assembly to the global assembly cache: MyProjectOutput.dll.”

Thanks to a few helpful blog and forum posts, the answer was this:

  1. Either retract solution from Visual Studio, and/or manually remove .dll from the GAC (C:\Windows\assembly)
  2. Close Visual Studio
  3. [Not sure if this is needed] Restart SharePoint Timer Service (SPTimerV4)

Also try these troubleshooting steps:

  • Recycle Application Pool or do an IIS Reset (could also add this as a Pre-Deployment step: Project Settings/SharePoint tab)
  • Put the dll in question into its own solution and deploy that once.  Leave your changes for your main project package.
  • Ensure that if you have multiple projects that reference that DLL (such as a Helper or Utilities class), that you are using the correct reference.  Possibly remove the project reference, and re-add.
  • Check to ensure that any FeatureActivating code is not busting something

Thanks to these references:

 

I hope to keep up the blogging now that things are cooling down!!
~ Sue

InfoPath book started

I have decided to start writing an InfoPath book that I intend to self-publish (most likely). If you have anything specifically you’d be interested in seeing, please let me know in the comments.

It’s been a while, my friends…

Hi everyone!

I’m still happily a SharePoint 2013 developer. I still work with InfoPath. I haven’t blogged in forever.

I am shortly returning to the blogging world. I will blog on PowerShell and JSLink.

Thanks for sticking around!

 

[On a personal note, also check out my new blog – I’m writing a book. From Zero to Hero – Journey of a Novelist

SharePoint 2013 – Recover deleted Default authentication Zone

Yes, yes, by the title you’re saying how in the world did you delete your default zone.  Well on my test platform I had installed a CU and it went horribly wrong, and in an effort to fix it, I mistakenly blew away the default zone.

Here's what I did to recover it:

$wa = Get-SPWebApplication "https://YourWebApplicationUrl.com"
$def = [Microsoft.SharePoint.Administration.SPIisSettings]::CreateFromExistingWebSite("IIS Displ Name")
$wa.IisSettings["Default"] = $def
$wa.Update()

So just go in to IIS Manager to make sure you have the right display name for the IIS web site related to that web application.

T-SQL query to get most recent 1 entry for each user

Hi, usually I write about SharePoint.  This week, I was attempting to get a list of all users on all the web applications on our Farm for the last 365 days.  Luckily one of our team members was already parsing through IIS Log files and writing the entries to a custom DB to be processed later.  These entries were written to the db basically exactly as they appear in the IIS Log – 1 entry for each and every page hit (I think he might have stripped out everything except .aspx pages).

So there’s currently 41,800,000 + rows in this custom DB, and really it’s still in a testing phase, because no indexes have yet been created on it (the concept is still being tested).  So I needed a way to say “Give me the Login Name and the URL of every unique user in the last 365 days, and the URL should be the most recent one from that unique Login Name, as long as it’s within 365 days”.

I haven’t used SQL in a while, and honestly I’m not a T-SQL guru, so I began to write a cursor to do this.  Yea.   Well 45 minutes later, when the query was still running and I had barely gotten a handful of anything, I thought there must be a better way.

I won’t go into the full explanations, because I don’t know if I’d be explaining it correctly, but here’s what I ended up with:

DECLARE @fromDate datetime
SET @fromDate = '5/5/2014'
SELECT RowNum, UserName, FullPageUrl, LastLogEntry
FROM (
   SELECT ROW_NUMBER() OVER(PARTITION BY logs.UserName ORDER BY logs.LogDateTime DESC) AS RowNum,
      logs.UserName, wa.Url + logs.Uri AS FullPageUrl, logs.LogDateTime AS LastLogEntry
   FROM IISLogs logs
      INNER JOIN WebApps wa ON logs.ApplicationId = wa.Id
) _
WHERE RowNum = 1
  AND LastLogEntry >= @fromDate
ORDER BY LastLogEntry ASC   -- or you could order by UserName or FullPageUrl

 

Basically this is saying Group By UserName, and only give me the first one, but take the first one in order of the Log Date in descending order.

This query took just over 5 minutes.  Also I have no idea why but the _ right before the last where clause absolutely has to be there.  I will look that up some other time.

SharePoint 2010 Error nativehr 0x80131904

We came across a strange error the other day, reported by a user in SharePoint 2010.   When the user attempted to add a new item to a Contacts list, the page threw an error.  When we debugged it on the server and showed the server error, it was basically as follows:

<nativehr>0x80131904<nativehr>
System.Runtime.InteropServices.COMException

with stack trace containing:

SPRequestInternalClass.AddOrUpdateItem
SPRequest.AddOrUpdateItem
SPListItem.AddOrUpdateItem
SPListItem.UpdateInternal

We looked in the ULS logs and found the following 2 errors:

  • No XsltListViewWebPart was found on this page[/path/siteColl/site/Lists/ListName/NewForm.aspx?IsDlg=1].  Hiding key filters and downgrading tree functionality
  • Cannot insert the value NULL into column ‘tp_DocId’, table ‘ContentDBName.dbo.AllUserData’; column does not allow nulls. INSERT fails.

From reading the blog that led me to the answer (below) there may also be an event log error, number 5586 (Unknown SQL Exception 515 occurred).

So I found a blog by Allen Wang about a similar problem he had with a survey.  SP2010 Survey List Error and Event ID 5586.  He explained in his post that when SharePoint owners add a certain number of columns to their List/Library, all of the same data type, that the SQL storage starts implementing what is called row wrapping.  So internally in the database, one of the columns is tp_RowOrdinal (NEVER EVER EVER EVER modify the DB directly), and this number gets increased once you go past the row wrapping limits (see below for PowerShell commands to see this).  Here’s a summary of the data types:

Single Line of Text:  Wraps after 64 columns
Mult Lines of Text:  Wraps after 32 columns
Choice:  Wraps after 64 columns
Number:  Wraps after 12 columns
Currency:  Wraps after 12 columns
Date/Time:  Wraps after 8 columns
Lookup:  Wraps after 16 columns
Boolean (Yes/No):  Wraps after 16 columns
Person/Group:  Wraps after 16 columns
Hyperlink/Picture:  Wraps after 32 columns
Calculated:  Wraps after 8 columns
GUID:  Wraps after each and every column
Int:  Wraps after 16 columns
Managed Metadata:  not sure, seems to be 4 or 6

Please reference this post from Microsoft (I know it’s 2013, but 2010 doesn’t seem to be around any more):  Software boundaries and limits.

So what had happened in our case was that there were over 78 columns in the list.  When the list Owner modified the column order to move the newly added columns to the top of the Edit/New form, that’s when it broke.  That was because RowOrdinal=1 was placed above RowOrdinal=0.

To see what I’m talking about without digging in the database, use PowerShell:

$web = Get-SPWeb https://yourURL.com/path/siteCollection/site
$list = $web.Lists["Name Of Your List"]
$field = $list.Fields.GetField("Field Display Name")
Write-Host $field.SchemaXml

This will output something like this

<Field Type="Number" DisplayName="Field Display Name" 
   ID="{89d9e81e-e31a-402d-a8e4-05935dbb29ac}" 
   SourceID="{9007df08-a644-461b-9af5-b39252f5bb93}" 
   StaticName="_x004e_um10" 
   Name="_x004e_um10" 
   ColName="float10" RowOrdinal="0" Version="1"/>

If you get the SchemaXml of the last few columns, you might see RowOrdinal=”1″ inside the SchemaXml.  If you see that, you cannot place that column above another column of the same type which has a 0 ordinal.  So for example this would be OK:

       NumberColumn10
       NumberColumn13

but this would break:

       NumberColumn13
       NumberColumn10

 

DISCLAIMER:

I just tried to replicate this in my VM of SP 2013 and I added over 500 number columns and over 100 user columns and was unable to get RowOrdinal to be anything but 0.  Not sure why.

Thanks to Allen Wang for providing solution.

Repost – Get an SPUser Object From a List or Library in SharePoint Using PowerShell (Brandon Atkinson)

This blog was written by someone else but appears to not be available right now.  I got this on cache.  I am re-posting it cause I had the hardest time tracking this down.  On reflection, it makes sense that you’d have to do it very similar to C# code, but I was stuck for a while.

THIS POST WAS WRITTEN BY BRANDON ATKINSON not me.  Following is the link, however it appears to not be working right now.  sharepointbrandon.com/category/powershell

I was looking this up for SharePoint 2010, however it most likely works the same in 2013.

Get an SPUser Object From a List or Library in SharePoint Using PowerShell

At some point in your journeys with PowerShell and SharePoint you’ll need to pull a user from a list/library column and get an email address or login name, etc.  If you’ve never done this before it can be a little frustrating as you have to jump through a couple of hoops.  Let’s take a look at simply querying the list.

Let’s assume we have a library with a Name column and a user column called “Owner”.  Now we can easily query the library and pull out the “Name” with something like this:

# $docLib is a reference to a library and $spQuery is an SPQuery object with a CAML query
$spListItems = $docLib.GetItems($spQuery)

# Loop through items and write out info
foreach ($item in $spListItems) {

    Write-Host $item.Name
}

In this example we simply query the library and loop through the results, writing out the ”Name”.  But what if we needed to also write out the email address of the user column.  Here is where the hoops come in, fortunately they are small.

You have to perform some casts in order to get the actual SPUser object.  So taking the previous example, we can re-write it like this:

# $docLib is a reference to a library and $spQuery is an SPQuery object with a CAML query
$spListItems = $docLib.GetItems($spQuery)

# Loop through items and write out info
foreach ($item in $spListItems) {

     Write-Host $item.Name

    # Get the SPUser object from the column
$spFieldUser = [Microsoft.SharePoint.SPFieldUser]$item.Fields.GetField(“Owner”);


$spFieldUserValue = [Microsoft.SharePoint.SPFieldUserValue]$spFieldUser.GetFieldValue($item[“Owner”].ToString());

$user = $spFieldUserValue.User;

   # Pull out the user email
Write-Host = $user.Email
}

In this example we first have to create an SPFieldUser object using $item.Fields.GetField(“Owner”).  Once we have that reference we can use the GetFieldValue method to return an SPFieldUserValue object, which will contain the actual SPUser object.  Now we have access to all the properties on the user like Email, DisplayName, LoginName, etc.

As you can see, its pretty easy to get to the user object in SharePoint via PowerShell.

Enjoy!

Problems publishing SPD 2010 workflows and InfoPath forms

So I have been working on a project on SharePoint 2010 that is basically a list where the input form has been customized using InfoPath.  We decided to go this route using a list instead of using a Forms library because of the capability in workflow to send dynamic emails to multiple people if and only if it comes from a Person or Group column.

The problem came when I got up around 75 columns.  Suddenly, I found that I could no longer publish the InfoPath form.  I got “The SOAP Message could not be parsed.”  If I removed a column or 2, or got rid of a rule, or a data connection, suddenly I could publish again.  But there seemed to be this magic, undefined breaking point that I couldn’t exceed before I’d start running into problems.

So now, I had to implement the SharePoint Designer 2010 workflow.  I knew I needed probably 3 workflows, one for create, and 2 for on change.  However, once I got past 2 or 3 IF statements, I could no longer publish the workflow either.  It would save, but on publish it would give me “Unexpected error on server associating the workflow.”  Now mind you, I did NOT have any Start Approval Process or similar actions – one of those content-type actions.  These were just simple conditions, emails, and setting of a few fields.

I found that I had to break my work up in to 16 workflows.  Each one started out with a condition to see if it should run.  This was getting ridiculous, and finally I got to a point where I couldn’t get any more granular and still it wouldn’t publish.  As suggested by some posts, I tried increasing $app.UserDefinedWorkflowMaximumComplexity in PowerShell (where $app is the SPWebApplication in question) and I also tried adding a timeout value to the  web.config.

 

So this whole time, I’m working from my contractor’s computer.  The SharePoint system in question was exposed over the internet using a UAG appliance for firewall and authentication.  Normally, this is not an issue, as I can usually get everything done I need to. On a whim I decided to open everything up from the customer’s computer, which incidentally has a VPN connection to their system, and voila, I can publish InfoPath forms and Workflows now with no issue.  <sigh>  It’s the little things that get you.

 

http://fairulshahrizat.blogspot.com/2012/12/sharepoint-designer-2010-workflow-error.html

 

SharePoint 2013 Sorry this site has not been shared with you

Recently I ran into an issue with a site that had been migrated from SharePoint 2007 through to SharePoint 2013.  The home page was a Publishing page in the Pages library, and the Pages library inherited permissions from the site, and none of the pages had unique permissions.  I had a couple of users who were in groups that had full control.  Those users were able to browse to the home page just fine, but when putting the page in Edit mode, received the message “Sorry, this site has not been shared with you.”

I went to the page in question and did a “Check Permissions” and sure enough they DID have rights – full control – to the page.

So I went into the SharePoint ULS logs and there was an Access Denied error logged, sure enough, but right around that error it was referencing something about the Publishing infrastructure.

 

So on a hunch, I checked permissions on the library at the root – Master Pages and Page Layouts.  Someone way back when had broken permissions on this library and removed EVERYONE’s permissions on this library except the system account and one administrator.  So I added the users to Full Control for the library (probably read would have sufficed, but they needed full control anyway) and the problem was resolved.

In general, you also want to be careful of permissions around the Style Library and/or Site Assets, depending on where your css files and images are stored.  We always have lots of people who think they are locking down their site remove the “Style Resource Readers” group (which by default has NT Authority\Authenticated Users in it) but the end result is no users can browse to anything because they don’t have rights to view the stylesheets.