Thursday, November 3, 2011

Q: I have a SQL Server Reporting Services report that uses a stored proc with three output parameters. How do I use the values of the parameters in the report?

The problem that you're having is that SSRS doesn't actually support SP output parameters. You have to wrap your stored procedure with another stored procedure that puts the output parameter value into a rowset. Here's a simple example. If you want, you can just copy & paste into a query in SQL Server Management Studio and it will work:


/*** Begin Example ***/
-- Setup
CREATE TABLE customers
  (
     customerid INT IDENTITY,
     firstname  VARCHAR(50),
     lastname   VARCHAR(50),
     custstatus VARCHAR(50)
  )
GO

INSERT customers
VALUES ('John',
        'Smith',
        'Active')
GO

-- First Stored Procedure, which uses output parameters.
-- This cannot be used directly in SSRS
CREATE PROCEDURE dbo.Usp_proc1 @CustID INT = 0,
                               @p1     VARCHAR(50) OUTPUT,
                               @p2     VARCHAR(50) OUTPUT,
                               @p3     VARCHAR(50) OUTPUT
AS
  SELECT @p1 = firstname,
         @p2 = lastname,
         @p3 = custstatus
  FROM   customers
  WHERE  customerid = @CustID
GO

-- Second Stored Procedure, which wraps the first one, converting
-- the output parameters into fields in a single-row rowset.
CREATE PROCEDURE dbo.Usp_proc2 @CustomerID INT = 0
AS
  BEGIN
      DECLARE @p1_output VARCHAR(50),
              @p2_output VARCHAR(50),
              @p3_output VARCHAR(50)

      EXECUTE dbo.Usp_proc1
        @CustomerID,
        @p1_output OUTPUT,
        @p2_output OUTPUT,
        @p3_output OUTPUT

      SELECT @p1_output AS cfname,
             @p2_output AS clname,
             @p3_output AS cstatus
  END
GO

-- Example invocation of the wrapper
EXECUTE dbo.Usp_proc2 1
GO

-- Returns a rowset like this:
-- cFNAME                 cLNAME            cSTATUS
------------------------- ----------------- ----------------------
-- John                   Smith             Active
-- Cleanup


DROP PROCEDURE dbo.usp_proc2
DROP PROCEDURE dbo.usp_proc1
DROP TABLE dbo.customers
/*** End Example ***/

Once you've made your wrapper, you can execute it in SSRS as a separate dataset, and use the fields directly. Depending on where you use it, it may be necessary to use it with, e.g. the "First" function, which is an aggregate function that simply means to use the first (in this case only) row returned from the stored procedure call.

Friday, April 8, 2011

Thursday, February 10, 2011

Q: How does Microsoft Dynamics NAV integrate with SharePoint 2010?

A: I'll be the first to say that I know virtually nothing about MS Dynamics, but the question was asked, and as it happens the MS Dynamics NAV team have a blog post entitled "Microsoft Dynamics NAV Compatibility with Microsoft Office 2010 and Microsoft SharePoint 2010 - Microsoft Dynamics NAV Team Blog - Site Home - MSDN Blogs", which outlines some of the compatibility features, e.g. similar user experiences, ability to query Dynamics ERP & CRM databases via SharePoint BCS, which in turn allows synchronization of MS Dynamics information to Outlook & SharePoint Workspace, etc., etc.

Q: How do I control who is allowed to create My Sites?

A: By using "Manage User Permissions" in the User Profile Service Application administration tool. The default is that all users get the "Create Personal Site" permission. To change this, remove "Authenticated Users" and "All Authenticated Users" from this permission and add the AD global groups to which you want to grant the permission. This blog post from SharePoint expert Dave Coleman gives the details: Locking Down My Site SharePoint 2010 - SharePointEduTech

Q: How many application pools does SharePoint set up by default?

A: If you run the SharePoint Farm Configuration Wizard, the answer is 6. Most of the service applications share one application pool (though of course you can safely change that after the fact). SharePoint MVP Spencer Harbar has listed them all in detail here: More on SharePoint 2010 Application Pools

Tuesday, February 8, 2011

Q: Is there a PowerShell equivalent to the C# "using" statement (for auto-disposing disposable objects)?

A: No. However, the PowerShell team very kindly came up with a simple implementation, detailed here:

Reserving keywords - Windows PowerShell Blog - Site Home - MSDN Blogs

It looks like this:

function using
{
param($obj, [scriptblock]$sb)

try {
& $sb
} finally {
if ($obj -is [IDisposable]) {
$obj.Dispose()
}
}
}

Here's the example:

using ($stream = new-object System.IO.StreamReader $PSHOME\types.ps1xml) {
foreach ($_ in 1..5) { $stream.ReadLine() }
}