The challenge: Create a SharePoint Content Database programmatically that uses Windows Authentication instead of SQL Authentication.
The answer: Although poorly documented, actually surprisingly simple.
In my current project, we had the need to programmatically create a Site Collection as part of a custom coded Workflow. Since that Site Collection will be holding archived data that could grow considerably over the years, there was also a design requirement that those programmatically created Site Collections exist in their own distinct Content Database. Well, easy enough, the object model supports creating a Content Database programmatically too, and then specifying that Content Database when you create the new Site Collection. Except that none of the overloaded methods for creating a Content Database appeared to support integrated Windows Authentication -- they all had parameters for the Username and Password of the database owner. The documentation for these methods doesn't say anything beyond the self-obvious parameter descriptions (i.e. the "DatabaseUserName" parameter is described as "A string that contains the name of the owner of the database." -- and here I thought that parameter was for ordering a pizza). There are no other remarks or other information about the ContentDatabases.Add method in the documentation.
For those familiar with the GUI Administration Page for creating a Content Database, there is a lovely little radio button to let you choose between Windows Authentication and SQL Authentication, and only after/if you specify SQL Authentication are the fields enabled for entering a username and password.
So, on a whim, I decided to see what happened if I called the Add method, but passed in null values for the username and password -- and guess what - it worked - the Content Database was created with Windows Authentication. I would say it worked as advertised, except this feature wasn't advertised anywhere - which probably means it will break in SharePoint 2010: The Search for More Money.
btw, for those of you using the stsadm "addcontentdb" command, the same is apparently true, just leave off the username and password parameters to create a database that uses Windows Authentication.
|
Eric C. Willman © copyright 1994-2010, all rights reserved.
No comments:
Post a Comment