1

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.

1

1 Answer 1

3

Unless it's a formatting issue with the question then the mod.Value = String.Format("", ...) is giving an empty string.

You want something like:

mod.Value = String.Format("<add name="{0}" connectionString="{1}" ProviderName="{2}" />", ...)
1
  • 1
    Per, thank you for the prompt response. Much appreciated...it works!!!! Regards. Apr 12, 2016 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.