开发者

Adding multiple content databases to Sharepoint

I am trying to create a new web applica开发者_如何学编程tion 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?


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜