21
May
10

Creating Logins and Users in SQL Azure

I recently needed to create a user with read only access to a SQL Azure database. I thought that this task would make for a good blog post, given thant managing users and access levels is a little differnet in SQL Azure than in a traditional hosted environment.

There is some good documentation out there SQL Azure supported TSQL syntax for doing these types of tasks. Here is a link to one resource that I found helpful: Managing Databases and Logins in SQL Azure

The first step is to create a new login. You will need to connect to the master database using your SQL Azure administrator account that you set up for your SQL Azure server in the developer portal, sql.azure.com. Here is the syntax I used:

CREATE LOGIN myreadonlylogin WITH password=’abc123‘;
SELECT * FROM sys.sql_logins;

The next step is to create a user in your SQL Azure database for this login. Disconnect from the master database, and connect to your SQL Azure database. Then, against your SQL Azure database, your can run the following syntax to create a user:

CREATE USER myreadonlyuser FROM LOGIN myreadonlylogin;

Finally, you need to assign this user permissions in this database. I ran the following to assign read only access:

EXEC sp_addrolemember ‘db_datareader’, ‘myreadonlyuser‘;

Hope this helps,
Joel

20
May
10

Aliasing Fieldnames in SharePoint

Anyone who has done any configuration in SharePoint knows the frustration involved with attempting to determine the actual fieldname within a SharePoint list.  The following table shows how a column defined as a  Site Column at a top level site can be aliased at the Site Column, Site Content Type, Web Content Type and List levels.

Name/Alias Source Level1 Level2 Level3
Team Site Column - - -
Team Name Site Column Site Content Type - -
Fav Team Name Site Column Site Content Type Web Content Type
My Fav Team Name Site Column Site Content Type Web Content Type List

Regardless of what I aliased the field name along the way to present to users, if I want to reference this field in a Content Query Web Part or custom code such as an Event Receiver, I need to reference it by the name “Team”.

There are a lot of posts about how to hack the CQWP to get it to show you all of the underlying field names, or to use the URL of the edit field page to show you the internal name of a field, but both of these are cumbersome and tedious, especially if I have access to a physical Development or Test server.  With PowerShell, I can write a very simple script to spit this information out:

cls
$siteUrl = “
http://marcs-lt”
$webName = “SiteDirectory”
$listName = “Sites”

$s = Get-SPSite $siteUrl
$w = $s.OpenWeb($webName)
$l = $w.Lists[$listName]
$l.Fields | Where-Object { $_.Hidden -eq $false } | Format-Table Title, InternalName –AutoSize

For those of you needing to do the same thing with 2007:

$siteUrl = “http://marcs-lt”
$webName = “SiteDirectory”
$listName = “Sites”

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
$site = New-Object “Microsoft.SharePoint.SPSite” -ArgumentList $siteUrl
$web = $site.OpenWeb($webName)
$list = $web.Lists[$listName]
$list.Fields | Where-Object { $_.Hidden -eq $false } | Format-Table Title, InternalName -AutoSize
$web.Dispose()
$site.Dispose()

Yeah, that’s great, but not too terribly useful :(

What I want to do is have a strongly typed domain object which will mimic the structure of the list so that I can use it without having to index the SPListItemCollection/SPListItem.  Good News, I can use this same script to generate a struct of fieldname which I can then use in building a domain object.  Here’s how:

$siteUrl = “http://marcs-lt”
$webName = “SiteDirectory”
$listName = “Sites”

$s = Get-SPSite $siteUrl
$w = $s.OpenWeb($webName)
$l = $w.Lists[$listName]
$l.Fields | Where-Object { $_.Hidden -eq $false } | ForEach-Object {

#using regular expression to replace ‘#’ with ‘Number’ and remove all bad chars
$fieldName = $_.Title -replace “#”, “Number” -replace “[!@#$%\&'\s()<>?:]“, “”
“public const string $($fieldName) = “”$($_.InternalName)”";”
}

Now my domain class could take an SPListItem as a paramerter into the constructor and build out my class like:

public class MyListItem
{
protected string teamName = “”;
protected string status = “”;

public MyListItem(SPListItem listItem)
{
if(listItem[Common.FieldNames.MyList.TeamFieldName] != null)
{
this.teamName = (string)listItem[Common.FieldNames.MyList.TeamFieldName];
}

if(listItem[Common.FieldNames.MyList.Status] != null)
{
this.status = (string)listItem[Common.FieldNames.MyList.Status];
}

. . .
}

public string TeamName
{
get{ return teamName; }
set{ teamName = value; }
}

public string Status
{
get{ return status; }
set{ status = value; } }

}

20
May
10

…Yeah but I do things other than SharePoint

Me too!  SharePoint is still a hog, which is why I don’t want the SharePoint services running on my developer workstation constantly when I’m trying to develop a WPF application, or write a proposal or … whatever.  There are a couple things we can do to reduce the overhead of SharePoint on my workstation so it does not suck up every last bit of available RAM.

  1. Throttle the RAM usage of SQL Server
  2. Isolate your Dev SQL Server instance from your SharePoint Instance
  3. Turn off Services in use by SharePoint

The easiest thing to do is to throttle your SQL Memory usage.

  1. open up SQL Server Management Studio (SSMS)
  2. connect to your instance
  3. View the properties of your instance
  4. choose the “memory” page
  5. adjust accordingly:

image

Next we want to isolate your SharePoint SQL instance.  If you use SQL Server Express and then install SharePoint, you are good to go.  As an all-in-one configuration, SharePoint will automatically install a SQL Server instance for SharePoint.  My feeling is that we should leave this instance to SharePoint for its own purposes.  Any other development should use a separate instance altogether.

Lastly, we want to effectively “Turn Off” SharePoint when we are not using it.  Here’s how:

We will use two PowerShell scripts to automate this for us. First, the Turn-On script:

start-service “mssql$*sharepoint”
start-service SPTimerV4
Start-Service SPUserCodeV4
Start-Service SPTraceV4
Start-Service SPAdminV4
Start-Service OSearch14
Start-Service SPSearch4
start-service W3SVC
IISRESET /timeout:0

The IISRESET command is probably redundant, but I want to make sure all of the services are in a good state.

And the inverse of this…The “Turn Off” script:

stop-service mssql$*sharepoint -force
stop-service SPTimerV4
Stop-Service SPUserCodeV4
Stop-Service SPTraceV4
Stop-Service SPAdminV4
Stop-Service OSearch14
Stop-Service SPSearch4
stop-service W3SVC
IISRESET /stop

Again, the IISRESET command is redundant, but I like it.

And to demonstrate the effects of this, here is a before and after of my workstation performance:

image

- Marc

06
May
10

Mobile Video and Advertising

Slalom Consulting extends its outreach to Midwest executives and the online community through an article on Mobile Video and Advertising, published today in Corp! Magazine online. The article was written by SlalomWorks blogger Jeff Barber.

06
May
10

A Microsoft Renaissance

It seems to me that Microsoft is going through a bit of a renaissance as of late.  Microsoft is a company that I feel no matter where your technology preferences lie, you’ve got to give them their due respect for, frankly, creating the industry we work in everyday.  Over the last 10 years or so it has seemed to me that Microsoft hasn’t been able to catch a break in a world of Googles and iPhones, but here we are in 2010, and to me, it looks like they are turning it around.

Search

Google hasn’t had much of a competitor in the search space for a while, and I’ll admit, when I first heard Microsoft’s latest effort was going to be called “Bing” I assumed it was yet another re-branding effort that wouldn’t amount to much.  Well I was wrong about that, at least if you look at their market share numbers which have been increasing steadily since launch.  I use Bing Travel all the time, I had been a fan of the technology since it launched originally as Seattle based startup Farecast, and their iPhone app is really quite good.

Windows

Windows Vista received a lot of criticism when it launched.  Many IT departments simply refused to adopt it, sticking with their tried & true Windows XP.  Windows 7 appears to have alleviated many of the issues that came a long with Vista and is getting far more praise and recently passed the 10% market share mark.

Cloud Computing

Microsoft’s cloud computing solution, Azure, is fairly young when compared the more well known Amazon Web Services, but that’s not to say they aren’t a competitor.  You can find many posts on this blog focused on how to leverage the Azure platform.  Microsoft’s model is decidedly different than Amazon’s.  They are following a Platform as a Service model by exposing their existing .Net and SQL technologies to developers in the cloud.  Amazon provides more of an Infrastructure as a Service model, exposing raw computing power in EC2.  Both approaches have merit, and can even work together, it is not unheard of for an enterprise to utilize both services.  Microsoft is making a big investment in the cloud and if Azure is any indication, they are definitely going to be a leader in the space.

Rich Internet Applications

Silverlight has made it to version 4.0 in a few short years.  In that time it has become a viable Flash alternative and adoption has been strong.  Microsoft is clearly standing behind the technology with even deeper integration into other Microsoft technologies, such as SharePoint, and the recent announcement that Silverlight will be the core technology for the upcoming Windows Phone 7 release.

Mobility

And last, but certainly not least, mobility.  Almost moments after the iPhone’s initial launch Windows Mobile’s market share began to drop.  In a world of high powered devices and platforms with mobile browsers capable of rendering nearly any website, the antiquated platform looked like it was on its way out, and in a way that is true.  Microsoft’s recent announcement of Windows Phone 7 is not just an upgrade of the old, but a complete re-imagining and re-design of how mobile devices based on Microsoft’s technologies will work.  They are taking a page out of Apple’s book by controlling the user experience  heavily and based on what has been shown so far, Microsoft is putting themselves back in the mix as a real competitor in the mobile space.  I’m excited to see how the platform stands up when it is launched in the fall.

- Greg

17
Apr
10

SharePoint 2010 Developer Workstation with Windows 7

There are several blogs about this topic also, but I thought I could add my $0.02 here after hitting a couple of stumbling blocks this afternoon.  I will be referencing the steps outlined here: Setting Up the Development Environment for SharePoint Server.

Step 1: Choose and Pre-configure the Operating System

I know, I know, it’s redundant, but it is still the truth and there is no way to fake it.  Your OS must be x64 and no N/KN builds.  Also, to avoid digging through massive maddening log files later, make sure that you have at least SQL Server 2008 version 10.00.2437.00.  Anything earlier than this build won’t work.  BTW…with SQL Server 2008 R2, you are automatically there.

Step 2: Install the Prerequisites for SharePoint 2010

This MSDN article explains how you can use the extract command to get this to work.  Alternatively, you can run the .exe here and it will automatically extract all of the files to c:\Program Files (x86)\MSECache\oserver2010.  This is important because one of the prerequisites (Microsoft FilterPack 2.0) must be installed from the extracted package.  I tried using a utility to perform the extraction (WinRAR); save yourself the headache as it will extract the files, but won’t respect the internal folder structure of the compressed file.  The full list of prerequisites, in order, are listed here:

Pre-Requisite Windows 7 Windows Vista Notes
.NET Framework 3.5 SP1 X
Windows PowerShell 2.0 CTP3 x64 X
Windows Installer 4.5 Redistributable X
Microsoft FilterPack 2.0 X X Can be found in the extracted files in .\PrerequisiteInstallerFiles\FilterPack\FilterPack.msi
Microsoft Sync Framework X X
SQL Server Native Client X X
Microsoft Geneva Framework Beta 1 Runtime for x64 X X
ADO.NET Data Services v1.5, X X which is required to support the REST service that is available at http://localhost/_vti_bin/ListData.svc. Choose the Runtime Only installer.
Chart Controls X X (this is not required if you are going to install SharePoint Foundation 2010).
SQL Server Analysis Services – ADOMD.Net X X (this is not required if you are going to install SharePoint Foundation 2010).

Step 3: Install SharePoint 2010

Two tips here:

1. Make sure you run setup.exe from the extracted files location.

2. Don’t run the prerequisite installer; this has already been done manually in the steps above.

That’s it.  Other than installing VS2010, but that should be relatively simple.

13
Apr
10

Recent Azure News

Here are a few interesting pieces of information regarding the Windows Azure Platform that have made some headlines recently:

- Joel

12
Apr
10

San Francisco Custom Dev Challenge!

The San Francisco Custom Dev Challenge is live at www.slalomchallenge.com!!!!!

Slalom Consulting employs world-class technical consultants who take on ground breaking projects. Please take the Slalom Custom Dev Challenge to see how you compare to the level of knowledge we look for in our technical consultants. The online quiz is focussed on General .NET at this time and will be growing to include other technical topics in the future.

This application is written in C#, and WCF running deployed in the cloud on Windows Azure and working with SQL Azure and Blob Storage.

08
Apr
10

The Power of PowerShell

With the new SharePoint PowerShell extensions that come with SharePoint 2010, we can do some pretty powerful stuff that was a little bit awkward with earlier versions of SharePoint.  In the past, I may have written a one-off console applications to iterate over sites looking for content, modifying that content and disposing of those objects.  That means, that I now have a full-blown executable that I need to put on the production server polluting what should be a pristine environment.  I could have also lazy-loaded the SharePoint assemblies with PowerShell and written the same scripts, which would not be very secure and possible cause memory leaks if I do not dispose of my variables correctly.  Now, I have native PowerShell commandlets to provide this functionality.  Here are a couple examples:

  1. I have a slew of webs which are all built off of the same site definition and all contain a list of events with the name “Case Schedule”.  I need a one-off mechanism to build a report showing the details of all events for a particular date range.

    $web = Get-SPWeb "http://<Site Url>"
    """Title"",""Event Date"",""Location"",""Description""" > Briefs.csv
    $web.Webs | %{
     
    $w = $_
     
    $l = $w.Lists["Case Schedule"]
     
    $l.Items | Where-Object { $_["EventDate"] -gt [System.DateTime]::Parse("1/1/2003") } | %{
       
    $li = $_
        [
    System.DateTime] $eventDate = $li["EventDate"]
       
    $startDate = $eventDate.ToLocalTime()
       
    """$($w.Title)"",""$($eventDate)"",""$($li['Location'])""$($li['Description'])""" >> Briefs.csv
      
      }
    }

    With Get-SPWeb I can now safely get access to a native SPWeb object as well as all of its members including .Webs, .AllProperties, .Lists, etc.  When this script is complete, I have a nicely formatted CSV.

  2. I need to push down data from production to my test environment so that I can keep them in sync.  This will encompass, un-mounting my content databases(es), restoring from my .bak file, re-mounting the databases and finally performing an IISRESET.  I can automate all of these tasks with a simple PowerShell script:

    param([System.String] $contentDatabase, `
        [
    System.String] $webApplication, `
        [
    System.String] $database, `
        [
    System.String] $instance, `
        [
    System.String] $location)

    #Load SQL Server 2008 Snapins
    Add-PSSnapin "SqlServerProviderSnapin100" 
    Add-PSSnapin "SqlServerCmdletSnapin100"

    $restore = "RESTORE DATABASE $($contentDatabase) FROM  DISK = N’$($location)’ WITH  FILE = 1,  
            MOVE N’$($contentDatabase)’ TO N’C:\Program Files\Microsoft SQL Server\MSSQL10.OFFICESERVERS\MSSQL\DATA\$($contentDatabase).mdf’,  
          MOVE N’$($contentDatabase)_log’ TO N’C:\Program Files\Microsoft SQL Server\MSSQL10.OFFICESERVERS\MSSQL\DATA\$($contentDatabase).LDF’,  
          NOUNLOAD,  STATS = 10
          GO"

    Remove-SPContentDatabase $contentDatabase -Confirm $false
    Invoke-Sqlcmd -Database $database -ServerInstance $instance -Query $restore
    Mount-SPContentDatabase $contentDatabase -WebApplication $webApplication -Confirm $false

Anyway, I have seen so many examples online for provisioning SP2010 service applications, I thought it would be nice to show some other real-world examples of how to use PowerShell in conjunction with SharePoint 2010 and other snap-ins.

Enjoy!


07
Apr
10

Silverlight’s Grid Control

With the direct integration of SharePoint with Silverlight, Silverlight now becomes an extremely flexible and viable tool for enhancing SharePoint’s default user interface.  With my current project, I have especially found that the Grid control with Silverlight 3.0 presents significantly better than SharePoint’s SPGridView control, which is how we used to have to display custom data to look like a SharePoint list.  As with any new technology, however, there are some pitfalls which I can hopefully shed some light on.

1. Grouping
Ever since SharePoint 2007 first came on the scene with its native ability to configure grouped tables within a grid control everyone has been trying to add this functionality to customized data, whether that was using third party controls or trying to retro-fit SharePoint’s SPGridView.  With Silverlight 3, this becomes trivial.  There are two classes which are necessary to implement this functionality.  1) PropertyGroupDescription 2) PagedCollectionView.  The PagedCollectionView object is instantiated with an IEnumerable source.  Once instantiated, one or more PropertyGroupDescription objects can be added to the collection of PagedCollectionView.GroupDescriptions.  The PropertyGroupDescription is instantiated with a string for the field name on which to build groups.  Therefore, if your underlying object has a property called DueDate, by instantiating your PropertyGroupDescription with the parameter “DueDate”, your grid will automatically group by that field.  Here is an example for those who don’t like to read:

Dispatcher.BeginInvoke(delegate

                          {

                            var webGroup = new PropertyGroupDescription("DueDate");

                            var pcv = new PagedCollectionView(e.SiteItems.OrderBy(item => item.Start));

                            pcv.GroupDescriptions.Add(webGroup);

                            grid.ItemsSource = pcv;

                          });

2. Friendly Names for Groups
Taking the above example, if I want to use friendly names for my group headers instead of the CamelCase DueDate, I can attribute the underlying DTO to get this.  Again, example below:

       [Display(Name = "Date", GroupName = "Date")]

        public string DueDate

        {

            get { return start.ToShortDateString(); }

        }

Now, when I render my grid, my headings will read Date: and not DueDate:  like below:

image

You will also notice, that by default I get a count of the items for that grouping.  Also very handy!