The request failed with HTTP status 401: Unauthorized in Report Services 2008 Sharepoint Integration

Today I tried to integrate Reporting Services and Sharepoint. The setup consisted of three servers:

  • SQL 2008
  • Reporting Services 2008
  • Sharepoint (WSS 3.0) with Reporting Services Addins

When I tried to connect Sharepoint to the Reporting Services Webservice using the Central Administration, I got the following error:

The request failed with HTTP status 401: Unauthorized

However when I manually visited the webservice through the browser @ http://myserver/ReportServer, everything worked fine. So why did the authentication fail for Sharepoint?

My Sharepoint setup uses NTLM authentication only, therefore Reporting Services must be configured for the same authentication type as well. After reading through tons of KB articles and posts, i finally found a solution to the problem:

  1. On the Reporting Services Server, open the config file rsreportserver.config (you find it in the Reporting Services folder)
  2. Look for the Autentication configuration node
  3. Remove the RSWindowsNegotiate setting

The config section in question should now look like this:


<Authentication>
  <AuthenticationTypes>
    <!-- <RSWindowsNegotiate/> -->
    <RSWindowsNTLM/>
  </AuthenticationTypes>
  <EnableAuthPersistence>true</EnableAuthPersistence>
</Autentication>

That way, only NTLM is used for authentication. This fixed it for me :)

Add existing users to Sharepoint in “Active Directory Account Creation Mode”

If you run a WSS 3.0 Farm in the so called Active Directory Account Creation Mode you can not add existing users to your site collection. You are restricted to users that were created in the respective site collection.

To work around this limitation, you can abuse the stsadm utility to publish an existing user into a site collection:

  1. Log in to your portal and create a new user, name it “dummy” with a non-existing E-Mail address like dummy@dummy.local
  2. On your Webserver, start a command prompt and navigate to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\Bin
  3. From there, run the STSADM utilty:

stsadm.exe -o migrateuser -oldlogin MYDOMAIN\dummy -newlogin MYDOMAIN\myExistingUser -ignoresidhistory

This will replace all Sharepoint-internal references to the dummy user by references your existing user. That way your existing user is visible in the isolated site collection.

Some notes about this techniques:

  • User attributes such as E-Mail, Title, Position, etc will not be updated along with the user SID.
  • If a user called dummy already existed, Sharepoint will create a User like dummy1 instead. I suggest you take a look at the dummy users creation date in Active Directory before issuing the stadm command.
  • Delete the dummy user after the migration.
  • The user references are being updated in the whole Sharepoint Farm.
  • If you dont specify -ignoresidhistory, the SID histories of both users will be compared for matches. And if there are no matches, the operation will fail.

Code faster!

A small hint for C# developers, check out the Visual C# 2008 Keybinding Reference Poster and hang it on your wall, I’m sure there are some shortcuts you didn’t know yet.

Right-align a TextBlock in Silverlight

There is currently no way to right-align a TextBlock UI Element in Silverlight, though you can use this workaround to properly position your TextBlock to make it appear right-aligned:

The XAML


<Canvas>
    <TextBlock Text="My Text" Loaded="TextBlock_Loaded" Width="80"/>
</Canvas>

The Loaded event handler


       private void TextBlock_Loaded(object sender, RoutedEventArgs e)
        {
            TextBlock tb = (TextBlock) sender;
            Canvas.SetLeft(tb, Canvas.GetLeft(tb) + tb.Width - tb.ActualWidth);
        }

By wrapping the TextBlock in the Canvas container, you can fix its position easily.

Dealing with DBNull in DataReaders

When dealing with IDataReaders in .NET, one faces the problem of catching DBNull values and properly converting them to ‘native null’:


int? myNullableField = (int?) reader["myField"]; // will FAIL if DBNull is being returned..

This extension method eases this pain and allows to retrieve the values in a null-safe way:


    public static class IDataReaderExtensions
    {
        public static Nullable<T> GetNullableValue<T> (this IDataReader reader, string fieldName) where T : struct
        {
            object value = reader[fieldName];
            if (value == DBNull.Value)
                return null;

            return (T) value;
        }
    }

Using the above extension, you can now simply use the reader this way:


int? myNullableField = reader.GetNullableValue<int>("myField");

The Nullable generic type does not work with certain types such as string, therefore the constraint T : struct is really essential to get it working. I borrowed this constraint trick from stackoverflow.com

Happy coding..

Silverlight object-tag problems in Firefox

Silverlight apps are embedded into web pages using the <object> tag. Now for some reason, Firefox refuses to instantiate the Silverlight application if the object-tag attributes are not in a certain order. As example, this won’t work in Firefox:


<object width="100%" height="100%"
data="data:application/x-silverlight-2" type="application/x-silverlight-2">

One has to position the data and  type attributes first to make it work, like this:


<object data="data:application/x-silverlight-2" type="application/x-silverlight-2"
width="100%" height="100%">

Strange bug..

Creating SVN patches and saving them as ZIP file

I use SVN as source control system for one of my projects. Sometimes I want to create patches in form of a zip file containing the changed/new files. Doing so manually is a pain and error prone. First you have to diff between your branches to find all change since your last release, export those files from SVN, then package them into a proper structured ZIP file.
So here is a PowerShell snippet doing exactly that automatically:


function new-patch
{
    param($from, $to)
    # get diff summary as XML
    [xml] $summary = (svn diff $to $from -x --ignore-eol-style --xml --summarize)
    # loop through all diff/paths/path nodes
    # each node represents a modified/new file
    foreach($item in $summary.diff.paths.path)
    {
        # the SVN url
        $url=$item."#text"
        # the relative filename
        $file=($item."#text".Substring($to.Length))
        # the parent directory
        $dir=($file | split-path -parent)
        # create parent directory if it doesn't exist already
        if((test-path $dir) -eq $false) { mkdir $dir -force}
        # export current files from the SVN repository
        svn export $url $file
    }
    # package the current dir (.) into patch.zip
    sevenzip.exe a patch.zip .
}

The function is then used like this:


PS> new-patch "https://actiongame.svn.sourceforge.net/svnroot/
actiongame/tags/v01_00_00/" "https://actiongame.svn.sourceforge.net/svnroot/actiongame/branches/v01_00_xx/"

I specified the old branch as first argument and the new branch as second argument. Now after processing I get all the changes as proper filetree inside a zip file. Ready to ship..

The whole process could be optimized quite a bit. Right now a new SVN request is sent for each single file, it could as well be batched into one request to improve the export performance.

Create .lib file from .dll

When working with 3rd party win dll’s you somtimes miss the according .lib file required to compile against it. There is a MS KB article showing how to generate a .lib file from a .dll, however the required steps are not described detailed enough I think. So here is my quick guide:

Open the Visual Studio Command Prompt, you find its shortcut in Start->Programs->Microsoft Visual Studio->Tools. Now run the dumpbin command to get a list of all exported functions of your dll:


dumpbin /exports C:\yourpath\yourlib.dll

This will print quite a bit of text to the console. However we are only interested in the functions:


ordinal hint RVA      name

1    0 00017770 jcopy_block_row
2    1 00017710 jcopy_sample_rows
3    2 000176C0 jdiv_round_up
4    3 000156D0 jinit_1pass_quantizer
5    4 00016D90 jinit_2pass_quantizer
6    5 00005750 jinit_c_coef_controller
...etc

Now copy all those function names (only the names!) and paste them into a new textfile. Name the nextfile yourlib.def and put the line “EXPORTS” at its top. My yourlib.def file looks like this:


EXPORTS
jcopy_block_row
jcopy_sample_rows
jdiv_round_up
jinit_1pass_quantizer
jinit_2pass_quantizer
jinit_c_coef_controller
...

Now from that definition file, we can finally create the .lib file. We use the “lib” tool for this, so run this command in your Visual Studio Command Prompt:


lib /def:C:\mypath\mylib.def /OUT:C:\mypath\mylib.lib

That’s it, happy coding :)

Apply jQuery effects in a sequence

Using the JavaScript library jQuery, you can apply effects to various DOM objects with ease. Each objects owns an effect-queue that is processed in a sequence. Fine, however how can we construct a sequence across multiple objects? Assume you have a list of titles in your website and you want to highlight them one after the other, not all at the same time. We can accomplish this by writing a simple function that applies the effects to the current object and continues with the next sibliing object.

Ok, assume we have this table and we wan to apply some effects to their rows sequentially:


<table id="features">
<tr>
<td>1a</td>
<td>1b</td>
</tr>
<tr>
<td>2a</td>
<td>2b</td>
</tr>
</table>

Now this script begins attaching the effects to the first row (”tr:first”). Our callback function seqfx is called when all effects on this object are processed, it will apply itself again to the next object and so on..

jQuery.fn.seqfx = function()
{
    $(this).fadeOut("fast").fadeIn("slow", function()
    {
        $(this).next().seqfx();
    });
};

$(document).ready(function()
{
    $("#features tr:first").seqfx();
});

This works fine and ensures sequential processing of all the table rows.

Colored ASP.NET GridView Cells

In Excel, there is a useful feature that lets you change the color of a cell depending on its value. As example, you could make a “total money” cell show up with a red background if its value is below zero. How can we do this with ASP.NET gridviews? There is no built-in functionality to make this work, you’ll need to write a few lines of code to get this done. Here is how I would solve this issue: Subscribe to the RowDataBound Event of your gridview, it is fired when the current row has been bound to data (filled with values):

GridView gv = new GridView();

gv.RowDataBound += new GridViewRowEventHandler(gv_RowDataBound);

In the according event handler, iterate through all cells and update their background-color based on their value:

// color last cell

void gv_RowDataBound(object sender, GridViewRowEventArgs e)

{

    if (e.Row.RowType == DataControlRowType.DataRow)

    {

        if (e.Row.Cells.Count > 0)

        {

            TableCell c = e.Row.Cells[e.Row.Cells.Count - 1];

            if (!string.IsNullOrEmpty(c.Text))

            {

                try

                {

                    int value = int.Parse(c.Text);

                    c.BackColor =

                        value >= 100 ? Color.LimeGreen :

                        value >= 85 ? Color.Gold :

                        Color.IndianRed;

                    c.Text = string.Format(“{0}%”, value); // add percentage sign

                }

                catch

                {

                    c.Text = null;

                }

            }

        }

    }

}

 

Done…

Next Page »