Thursday, May 15, 2008

How to map Windows domain user group to SQL Server 2005 database object permission setting

I was very disappointed when I found out I can’t directly map Windows domain user group to SQL Server 2005 database object permission setting. While you can add a Windows domain user to Security-Logins, and then assign database object permission setting to the Windows domain user account, you can’t do the same to user group. Object permission has to be associated with a user.

I found a doable way to workaround this problem, though. In SQL Server Management Studio:

  • For each database I need to create a Database Role, say “MyAppAdminUser”.
  • Right click on the Windows domain user group, select Properties. In Login Properties window, select User Mapping. In the “User mapped to this login”, check the database, and then check the Database Role we just create (“MyAppAdminUser”.)
  • Finally, configure all database object permission for MyAppAdminUser.

Now whatever right “MyAppAdminUser” gets will be the right the domain user group gets.

Add Windows domain group into SQL Server 2005 Login list

To add a Windows user group as a SQL Server 2005 login:

  • Under Management Studio, right click on Security\Logins, and select "New Login ...".
  • In the "Login - New" window, click [Search..]
  • Check the "Groups" checkbox, then click [OK]
  • Click [Advnaced]
  • Click [Object Types]
  • Make sure the location is listing the right machine or domain, otherwise click [Locations...] in case you need to change.
  • Click [Find now]
Your domain group should be in the list.

Thursday, May 01, 2008

Use XmlPoke to replace Xml node

My goal was to update the project file (.proj) of a Visual Studio 2008 project in NAnt script. At first I thought it was a simple task, and I found all the knowledge I need to learn and figure out the proper XPath to find the path I need to modify:

/Project//PostBuildEvent

However, I couldn't get the script XmlPoke running. After a while, I realize that the code WILL run if I take out the name space reference in the project file:

xmlns="http://schemas.microsoft.com/developer/msbuild/2003"

I looked into Nant's manual, and found out how to specify namespace entry. But I have problem figuring out what namespace prefix I should use.

Finally I came across this post, which gave me the exact way to write it. So here it goes:


    <target name="SetEnviornmentForBeforeCompilation">
<xmlpoke
file="Configuration.csproj"
xpath="/ns:Project//ns:PostBuildEvent"
value="$(TargetPath) $(SolutionDir) BUILD" >

<namespaces>
<namespace prefix="ns" uri="http://schemas.microsoft.com/developer/msbuild/2003" />
</namespaces>
</xmlpoke>
</target>