Getting your SQL Server databases under source control

Here’s a tip – There is a free download available called SQL Server Data Tools that lets you put your databases into source control (I’m using TFS).

Check it out here – http://msdn.microsoft.com/en-gb/data/tools.aspx

It comes with the facility to do a schema compare which is useful just in itself if you havent shelled out for Redgates SQL Compare.  It only compares schemas though, not data.  However it will apply changes to a database for you, so for example you can compare your files in source control with the dev/live database and then apply any differences with the click of a button.

I’m hoping to use this to facilitate continuous integration and have an automated test build of our data warehouse databases – I will post back with details when it’s all set up and running.

Populate/maintain a sharepoint list using SSIS

Ever wanted to get data from your database onto sharepoint?  Need to populate a list fast?  Here’s how…

Firstly you need an addin for BIDS – http://sqlsrvintegrationsrv.codeplex.com/releases/view/17652

Add this to your toolbox items and you can create SharePoint lists as source / destination.

Dont have much time to flesh this out but wanted to keep the link above for future reference. 🙂

SharePoint 2010 User Profile Service vs. NETBIOS

Recently I’ve had a niggling problem with SharePoint 2010 UPS – My user profiles were appearing with the wrong domain prefix and it was throwing out the people pickers and org charts in my sites.

It boiled down to the fact that our company NETBIOS name for the domain doesn’t match the first part of our fully qualified domain name.

E.g. NETBIOS name is DanCorp but FQDN is corp.dan.com

The problem here is that SharePoint has a setting called NetBIOSDomainNamesEnabled which by default is set to False.

The solution is to set this to True (see below), then delete your AD connection in Central Admin, recreate it and run a full sync.

BEWARE – Our tech support guys tried this with deleting the AD connection and it made our domain controllers VERY upset, we had user authentication issues all over the place.  If you follow the steps below you should be fine but be sure to delete and recreate the connection to AD in Central Admin before running a synchronisation.

Step by step

1) set NetBIOSDomainNamesEnabled to True through Powershell (script below)

2) Delete the sync connection in Central Admin (‘Configure Synchronisation Connections’ on the manage user profile service screen).

3) Recreate the connection.

4) Run a full synchronisation.

Powershell script (save this as a .PS1 file and run it using ‘SharePoint 2010 Management Shell’)

$ServiceApps = Get-SPServiceApplication

$UserProfileServiceApp = “”

foreach ($sa in $ServiceApps)

{if ($sa.DisplayName -eq “User Profile Service”)

{$UserProfileServiceApp = $sa}

}

$UserProfileServiceApp.NetBIOSDomainNamesEnabled = 1

$UserProfileServiceApp.Update()

Annoying prompt opening PDFs in SharePoint 2010

Today I came across an issue where I created a doc library and uploaded some PDFs to it – When you click on a PDF it popped up a prompt saying open read only or edit.

When would I want to edit a pdf? (not very often in my case) – So I wanted to get rid of this.

Jess Collicot gave the answer (http://www.deliveron.com/blog/post/Fixing-Prompts-When-Opening-PDFs-in-SharePoint-2010.aspx)

Basically you have to edit an XML document in the 14 hive of your sharepoint server(s) – The document is called DOCICON.XML and can be found in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML (or your equivalent 14 hive location)

Find the node starting <Mapping Key=”pdf” Value….

and add OpenControl=”” to the end (inside the triangular brackets) – Mine now looks like this…

<Mapping Key=”pdf” Value=”pdficon.gif” OpenControl=”” />

Then a quick IIS reset and the prompt is gone – PDFs now open straight in the browser nice and quick. 🙂

Renaming / moving projects and solutions in BIDS

Something that has annoyed me plenty in the past but I’ve never bothered to figure it out properly, well it happened to me again today so I though I should put it to bed once and for all.

Lets say you create an SSIS project in BIDS, play with it for a bit, then decide you need another project in that solution – So you add your project and find your solution is named after your first project.

Renaming the solution in BIDS is easy – The problem is if you look in windows explorer the main folder for your solution is also named after your first project – You want to change this to match the new name of you solution.

So you rename the folder in windows explorer and suddenly you can’t open your projects in BIDS anymore – It doesnt know where they are any more.

The trick is to edit the .sln file for the solution in notepad – You will need to change the file to not be read only first (I also ran notepad as admin for good measure).

Once in notepad you will see a couple of places where you need to change the path to match your new folder name (see example below)

Make the changes to reflect what is now the case (ie what you see in windows explorer) – Save the file, then re-open in BIDS and all should be good with the world!
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project(“{D183A3D8-5FD8-494B-B014-37F57B35E655}”) = “xLoadLoad”, “xLoadLoad\xLoadLoad.dtproj”, “{84171A3D-08EF-4E73-B60A-7EBA421F58EE}”
EndProject
Project(“{D183A3D8-5FD8-494B-B014-37F57B35E655}”) = “xDWHLoad”, “xDWHLoad\xDWHLoad.dtproj”, “{90639253-2455-4D72-9C2A-269F6C259E2A}”
EndProject
Project(“{D183A3D8-5FD8-494B-B014-37F57B35E655}”) = “xStageLoad”, “xStageLoad\xStageLoad.dtproj”, “{75B18651-AEA6-41B8-BE5B-7B351FEBD1DC}”
EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 4
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = xxx
SccLocalPath0 = .
SccProjectUniqueName1 = xDWHLoad\\xDWHLoad.dtproj
SccProjectName1 = xDWHLoad
SccLocalPath1 = xDWHLoad
SccProjectUniqueName2 = xStageLoad\\xStageLoad.dtproj
SccProjectName2 = xStageLoad
SccLocalPath2 = xStageLoad
SccProjectUniqueName3 = xLoadLoad\\xLoadLoad.dtproj
SccProjectName3 = xLoadLoad
SccLocalPath3 = xLoadLoad
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Development|Default = Development|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{84171A3D-08EF-4E73-B60A-7EBA421F58EE}.Development|Default.ActiveCfg = Development
{84171A3D-08EF-4E73-B60A-7EBA421F58EE}.Development|Default.Build.0 = Development
{90639253-2455-4D72-9C2A-269F6C259E2A}.Development|Default.ActiveCfg = Development
{90639253-2455-4D72-9C2A-269F6C259E2A}.Development|Default.Build.0 = Development
{75B18651-AEA6-41B8-BE5B-7B351FEBD1DC}.Development|Default.ActiveCfg = Development
{75B18651-AEA6-41B8-BE5B-7B351FEBD1DC}.Development|Default.Build.0 = Development
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

No credits for this one as I worked it out myself 😀

SSRS – Passing Multi-Value parameters between reports

Not posted for a while but this one was worth remembering…

In order to pass multi-value parameters from one report to another you need to use a combination of the following:

StrToSet – MDX function that converts a string to an MDX set

Split – An SSRS expression function that create an array object from a comma seperated string

Join – An SSRS expression function that create a comma seperated string (in this case from a set of parameter values)

In both reports you need a parameter that is set to accept multiple values – Lets call it prmMulti (in both reports, although the name could be different in each report)

The parameter should have values that look like MDX members ie [dimension].[attribute].&[member] – You can use currentmember.uniquename for this.

In the parent report go to the text box you want to click to drill to the child report and under navigation/action select prmMulti and enter an expression for the value to pass down as follows:

=Split(Join(Parameters!prmMulti.Value,”,”),”,”)

The join function creates a comma seperated list from all the selected parameter values and the split function then converts this into an array object – This is what gets passed to the child report.

Thanks go to Erika for this one – http://erikasblog.datainspirations.com/2010/01/21/passing-multi-value-sql-parameters-to-an-mdx-query-in-reporting-services/

Self documenting database (SQL Server)

Like most developers (and in fact most sane people) I dont like doing documentation, however you can’t deny the value of it so I went about trying to see how it could be done in SQL Server without having to buy some software or have a prolonged fight with MS Word!

A quick google led me to the extended properties page of a columns properties (in management studio)

You can add all the extra meta data you require here specific to your project, in this example I’ve added 3 extended properties – Source, Frequency loaded and Owner.  I’ve then given these properties values for this particular column.

That meta data is then stored against the column’s id in a system table called sys.extended_properties, we can see this by running a quick select statement:

Now all we need to do is pivot this so we get one row with all the extended properties as columns and we can join onto the INFORMATION_SCHEMA.COLUMNS system view using the major and minor ids.  I have had to do a bit of jiggery pokery in order to not have to specify the names of the extended properties (we wont necessarily know what they are all the time!).  I dont have time to go into it in detail but have a look at the comments in the code below and it should hopefully make sense.

declare

 

@names asvarchar(100)

 

declare

 

@sql asnvarchar(max

 

 

— populate @names variable with the columns we want to include in our PIVOT statement

select

 

@names =coalesce(@names +‘, ‘,)+ name from

sys.extended_properties ep 

— build up the sql for the PIVOT statement (including the columns names captured above)

set

@sql =  

‘SELECT major_id, minor_id,

+ @names +‘into ##tmp

FROM

(SELECT name, value, major_id, minor_id

FROM sys.extended_properties

WHERE class = 1) AS SourceTable

PIVOT

(

max(Value)

FOR name IN (‘

 

 

+ @names +‘)) AS PivotTable’

 

 

— run the sql to save this data in ##tmp

exec

sp_executesql@sql

— Bring it all together by pulling the columns details from information_schema

— and then joining on the extra metadata gathered above

SELECT

TABLE_NAME

, COLUMN_NAME, COLUMN_DEFAULT,c

.IS_NULLABLE,case

whencast(DATA_TYPE ASvarchar(10))like‘%char%’  

thencast(DATA_TYPE ASvarchar(10))+‘(‘+replace(cast(CHARACTER_MAXIMUM_LENGTH ASvarchar(6)),‘-1’,‘max’)+‘)’ 

else data_type end,ep

.*FROM

INFORMATION_SCHEMA

.COLUMNS cINNER

JOIN

 

sys

.columns scON

OBJECT_ID

(c.TABLE_SCHEMA +‘.’+ c.TABLE_NAME)= sc.[object_id]

AND

c.COLUMN_NAME = sc.name

LEFT

OUTERJOIN

 

##tmp ep

ON

sc

.[object_id] = ep.major_idAND

sc.[column_id] = ep.minor_id

ORDER

BY

 

1

, 2; 

 

Create a comma separated string

I just used this again after 2 years so though I should flesh out the description a bit.

This is really useful if you need to quickly create a delimited string based on a GROUP BY statement.

The example below illustrates this using a simple set of sample data.

select 1 as id, ‘frog’ as name into #tmp
insert into #tmp (id, name) values (1,’toad’)
insert into #tmp (id, name) values (2,’cat’)
insert into #tmp (id, name) values (2,’dog’)

SELECT p1.Id, ( SELECT Name + ‘,’ FROM #tmp p2
WHERE p2.Id = p1.Id ORDER BY Name FOR XML PATH(”) ) AS list
FROM #tmp p1 GROUP BY Id ;

Excel Services in SharePoint 2007 and 2010

Over the past couple of weeks I have been helping colleges get their Excel Services working on both 2007 and 2010 so that they can create reports in Excel which source data from an Analysis Services instance on another server.

Given that these have been multiple server environments we have been configuring the dreaded Kerberos authentication to get over the double-hop issue.

What I’ve realised is that the steps required on SharePoint 2010 are pretty different to the steps required on MOSS 2007 – There are a few reasons for this, mainly that MOSS 2007 uses SSPs and SP2010 doesn’t and also because SP2010 uses claims authentication which requires the configuration of the C2WTS service (Claims To Windows Token Service).

More to come on this as and when I get the time however in the meantime here are some useful links if you’re troubleshooting…

SP2010 – http://powerpivotgeek.com/2010/02/08/the-data-connection-uses-windows-authentication-and-user-credentials-could-not-be-delegated/

http://blogs.msdn.com/b/andrasg/archive/2010/05/04/setting-up-sharepoint-2010-excel-services-to-get-external-data.aspx

There is also this document http://go.microsoft.com/fwlink/?LinkID=196600 – Excel Services 2010 guide starting at Page 89.

Note – Read the document carefully! If you do everything it says you should be ok.  It’s easy to miss something so if you think you’ve done it all and it still isnt working review it again.  Something as simple as not adding a service account to the local administrators group can break the whole thing.

MOSS 2007 – http://blogs.msdn.com/b/martinkearn/archive/2007/04/27/configuring-kerberos-for-sharepoint-2007-part-2-excel-services-and-sql-analysis-services.aspx