SharePoint 2010 standalone, SQL Server and no sysadmin privileges

Good news for developers – SharePoint 2010 can be installed on your workstations running Windows 7 or Vista x64. There is a good MSDN article describing the installation process – everything went smoothly on my Windows 7 Ultimate x64.

When WSS 3.0 or MOSS 2007 was installed in standalone mode, it used Windows Internal Database as its backend. For SharePoint 2010 this is no longer true – the installer puts up a named instance (with SHAREPOINT as the instance ID) of SQL Server 2008 Express. This is a fully functional Express instance, but there is still at least one gotcha – the user that installed SharePoint 2010 has no administrative privileges to this SQL Server instance. What if you really need those privileges?

Fortunately, there is a way (or maybe even multiple ways) to get the privileges you want. It’s fairly simple – SQL Server needs to be restarted in single-user mode, so that any member of the Windows Administrators group can login to SQL Server with sysadmin privileges. That administrator grants the required privileges to users, logs out and restarts SQL Server in normal mode.

I have written a simple batch script that accepts two parameters – the computer name and the user that needs to have sysadmin privileges. Here it is:

net stop mssql$sharepoint
net start mssql$sharepoint /m "sqlcmd"
sqlcmd -E -S %1\SHAREPOINT -Q "CREATE LOGIN [%1\%2] FROM WINDOWS; EXEC master..sp_addsrvrolemember @loginame = N'%1\%2', @rolename = N'sysadmin';"
net stop mssql$sharepoint
net start mssql$sharepoint
iisreset

For example, to grant privileges to user JanuszM working on a computer named ITCNG, the following syntax would do the trick (provided that the above script is saved to a file named sp2010_grant_sysadmin.bat):

sp2010_grant_sysadmin.bat ITCNG JanuszM

If you’re wondering why I’m using /m “sqlcmd” instead of just /m, the answer is simple – because it’s single-user mode and only one user can connect to SQL Server. Restricting the connections to sqlcmd almost guarantees that no other running service will acquire that connection and our user will be able to connect and perform the required grants.

SharePoint 2010 Beta available for download