I wrote the following code in my feature receiver to add a connectionString in the web.config:
SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://devtools2012/sites/Test"));
SPWebConfigModification mod = new SPWebConfigModification("add[@name=\"MyConnection\"]",
"configuration/connectionStrings");
mod.Owner = "ExcelServiceOwner";
mod.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
mod.Value = String.Format("", "MyConnection", "Server=DEVWCMSDB2012;Database=BJS;Integrated Security=true", "System.Data.SqlClient");
webApp.WebConfigModifications.Add(mod);
webApp.Update();
webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
However, it is failing with the following error:
Failed to apply web.config modifications to Web application '9a38b727-bab9-44ad-93ba-a6c3b919d481'. Failed to apply web.config modifications to file 'C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config'. The Value property for EnsureChildNode cannot be set to an empty value.
I appreciate any input you can extend me. Regards.