[SQL Server] – Check Restore / Backup progress

Having to temporarily wear the DBA hat for a couple of days, I found myself backing up and restoring lots of databases, across different environments.

When you script the backup/restore, you can choose to output the progress, but if you run the backup/restore inside a SQL agent job, you won’t have any feedback until the job has finished.

But fear not, you can have some insights on the progress using the following query


   t.text Command,
FROM sys.dm_exec_requests e
CROSS APPLY sys.dm_exec_sql_text(e.sql_handle) t


And there you go!

Some databases can remain on 100% completion for a while, just be patient.

Where are SQL Server Error logs stored?

Lately I had to provide the location of our SQL server error logs to an infra team, so they could be copied somewhere else.

Raising a ticket and asking the DBAs is always an option, but as usual will introduce some latency.

No worries, there’s a command we can run  to get hold of the error logs location:

exec sp_readerrorlog

This will return a set of text rows, one of which says something like:

2015-10-07 01:52:07.770 Server       Logging SQL Server messages in file ‘ERROR LOG PATH‘.

The problem is that I didn’t have any other rights on this SQL server, other than select permission, so it was impossible to execute this procedure.

Fear not, dear friends, there’s another way, using a simple select:


and this will return the exact error log path!



Sharepoint 2013 – some thoughts about sticky footer the sharepoint resize event and DOM breakpoints

Lately on a SP 2013 project where we had a sticky footer, we were facing a problem lots of people currently face: SharePoint calculates the height (and width by the way) of the s4-workspace div based on the window object size.

It means that the workspace does not consider the footer, and when the content needs a scroll, the scroll is hidden behind the footer.. not cool :|

After spending some time and hitting the wall, I got a solution that’s not too ugly..

1st try
Add an event listener to the window resize event and subtract from the s4-workspace height the height of the footer.  And it worked…. for a second only.. then the SP event that recalculates the size would override it again. It was a dead end.

2nd try
It become obvious that I needed to understand what method was being called by SharePoint to calculate the sizes. But I didn’t find a way to see all the event listeners attached to the window element.

Then I looked at the problem from another angle. What do I know?

I know SharePoint is changing the size of the s4-workplace div. How can I find where and how does he do that? The answer is the DOM breakpoints.

Using Chrome developer tools, I selected the s4-workspace div and the selected “Break On…”, “Attributes modifications”:

dom breakpoints

Then I resized the browser window and the code stopped on the exact spot where a modification for the workspace div attributes was operated. The function happened to be on the global scope, and the only function on the call stack:


So now that I know that the name of the function that SharePoint uses to calculate the size of the workspace div, I can remove the height of the ribbon. I did it by saving the original function to a variable, and replacing the function with a new one that calls the original one and right after removes the footer height from the workspace div:

var originalResizeFunction = FixRibbonAndWorkspaceDimensions;
FixRibbonAndWorkspaceDimensions = function()
    //let sharepoint do its thing

    //adapt to the footer size (assuming  #footer is the footer element)
    $("#s4-workspace").height($("#s4-workspace").height() - $("#footer").height()

Remember to call this script after the init.js of SharePoint is loaded. Do it either at the end of the DOM or use the ExecuteOrDelayUntillScriptLoaded method.

Now the workspace adapts perfectly to the footer and the scrollable content does not hide behind it.


[Javascript] – Parsing integers with trailing “0” with parseInt

We are always learning, sometimes not the best way :)

As most of the times, when I develop in JavaScript, I end up using the chrome debugger as it’s lighter than its IE counterpart.

On a project, I had to retrieve some dates from DOM elements and process them, place the elements in the proper position.

The dates were on the following format: “MM:YY”. It means that February is “02” and September is “09”.

While on chrome the parsing of those texts were ok:
parseInt(“02″) -> 2
parseIng(“09″) -> 9
on IE9 and IE11 they were inconsistent:
parseInt(“02″) -> 2
parseInt(“09″) -> 0

Apparently parseInt works in OCTAL mode by default when the string starts with a “0”. Since in octal mode 8 and 9 don’t exist, it returns 0, for IE 8 Document mode.

Like it or not, it is designed like that, when you use IE 8 Document Mode (which you necessarily use for sharepoint 2010).

JsBin (set your browser to IE 8 Document Mode and ignore the JSBIN javascript errors caused it causes):

So, it’s necessary to force the decimal mode:
parseInt(“09″,10) -> 9

So from now on, I’ll always specify the decimal mode, just in case.

Add a security trimmed node to Sharepoint top bar navigation

After programatically provisioning a new SPWeb object, it is sometimes necessary to create a new entry on the root web top bar menu.
So far so good, but what happens if the subsite has different permissions from the root site. What if someone with access to the root site sees the menu entry for a site that he’s not entitled to see?

The following piece of code allows the creation of the menu node with swcurity trimming: only the users with permissions on the sub-sites will see the nodes on the menu.

Lets take for example the baseWeb onject as the root SPWeb and the provisionedWeb object as the recent provisioned one.

public void aaa()
        var menuNodes= baseWeb.Navigation.TopNavigationBar;
	// Check for an existing link to the subsite.
	SPNavigationNode newNode = menuNodes
		.FirstOrDefault(n => n.Url.Equals(siteNew.ServerRelativeUrl));
	// No link, so add one.
	if (newNode == null)
		// Create the node.
		newNode = new SPNavigationNode(provisionedWeb .Title, provisionedWeb .ServerRelativeUrl);
		// Add it to the collection.
		newNode = menuNodes.AddAsLast(newNode);

[Sharepoint] Adding a field to a list view with code -> don’t use the DefaultView property

Today we faced a strange problem doing  a task as simple as adding a field to the default view (“All items”) with code.
The code would run inside a feature activation and it was something like this:

 var view = list.DefaultView;

But… even after the update, the viewfields property remained unchanged…. The view reference was pointing to “All Items”, which was correct, all the existing viewfields were retrieved correctly, but we were unable to add one.

The next logical thing to do was to reference view differently. Referencing it by it’s name did the job. So the working code doesn’t change a lot:

 var view = list.Views["All Items"];

But still it made us loose precious minutes of our time to get to the solution…
Hope it’s useful to you!


[Sharepoint] Target a single organizational unit of the Active Directory from a Site Collection

One of these days I had a challenging request: create a “multi-tenant” sharepoint app using a single instance and the same Active Directory.

This application was supposed to allow several companies to use a specific part of it.

For scalabilty reasons it was decided that this segregation could not be done at web application level – what would have made things easier- so the separation will be done at site collection level.

Continue reading “[Sharepoint] Target a single organizational unit of the Active Directory from a Site Collection” »

Referencing JSON.NET in Windows Phone 8

Sometimes we just want to knock our heads against the wall until the wall cracks or we loose our senses…

That’s how I feel now, after loosing more than 30 minutes figuring out how reference JSON.NET in a Windows Phone 8 Project.

So, I took the Silverlight assembly, and added it to the project and this is what I got:  a nice “A reference to a higher version or incompatible assembly cannot be added to the project.” error message..

Continue reading “Referencing JSON.NET in Windows Phone 8” »