views:

32

answers:

1

I am trying to create a new web application in Web service. I am using this code to do this.

        SPWebApplicationBuilder webAppBuilder = new SPWebApplicationBuilder(SPFarm.Local);
        webAppBuilder.Port = port;
        webAppBuilder.RootDirectory = new System.IO.DirectoryInfo(@"C:\Inetpub\wwwroot\wss\VirtualDirectories\" + port);
        webAppBuilder.CreateNewDatabase = true;
        webAppBuilder.DatabaseName = "WSS_Content_00000000000000000000000000000000";
        SPWebApplication newWebApplication = webAppBuilder.Create();
        newWebApplication.Provision();

Now I wand to add a new content database to the same web application. According to my understanding I can use this to do it.

newWebApplication.ContentDatabases.Add(new SPContentDatabase());

The new operator should create a new content database instance this is not successful. (NullReferenceException). And the IDE suggests me to use new operator even I already use it.

Any idea on this? Any reference on adding multiple content databases?

+2  A: 

You can't add a new content database without specifying the database information. Your code just creates an empty SPContentDatabase object without any server, database name or connectivity information. The NullReferenceException probably occurs when the Add method tries to access a database property that was never initialized.

Try to use the Add variants that accept database information directly, like this

newWebApplication.ContentDatabases.Add("Database_Server", "Database_Name", 
                                               null, null, 1000, 1000, 0);
Panagiotis Kanavos
+1 and accepted :). However I think there is a mistake in MSDN article. You can't have the site number warning and maximum site number the same.Maximum number of sites should be higher... :)
Chathuranga Chandrasekara