I have a fairly simple custom Visual Web Part project with two Visual Web Parts in it. If I hard code the Connection String in the web.config file, everything deploys and works fine.
Now I removed the <connectionStrings> section from web.config to put it back like it was before I manually edited it. I'm using a blog post (http://selingernetwork.com/blog/?p=45) to try to get the Connection Strings added programmatically. I have a single Package with two Features. One Feature is Farm scoped and has the Event Receiver added. The other Feature is Site scoped and simply contains the two Visual Web Parts.
The project builds fine. When I try to deploy the project I get:
Error occurred in deployment step 'Add Solution': Unexpected end of file has occurred. The following elements are not closed: Line 1, position 212.
If I comment out the line webService.ApplyWebConfigModifications(), it deploys without error, but obviously doesn't work.
Here is the EventReceiver class with the connection string hard coded in it for now to eliminate variables:
private static readonly string connString = "Data Source=SQL-SERVER;Initial Catalog=Database;uid=sa;password=Password;Encrypt=true;TrustServerCertificate=true;"; public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWebService webService = (SPWebService)properties.Feature.Parent; SPWebConfigModification ensureConnectionString = new SPWebConfigModification(); ensureConnectionString.Owner = "connectionStrings"; ensureConnectionString.Path = "configuration"; ensureConnectionString.Name = "connectionStrings"; //ensureConnectionString.Value = "connectionStrings"; ensureConnectionString.Sequence = 0; ensureConnectionString.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureSection; webService.WebConfigModifications.Add(ensureConnectionString); ensureConnectionString = new SPWebConfigModification(); ensureConnectionString.Owner = "HotListWebPart"; ensureConnectionString.Path = "configuration/connectionStrings"; ensureConnectionString.Name = "add[@name='CustomConnectionString']"; ensureConnectionString.Value = string.Format("<add name='CustomConnectionString' connectionString='{0}' providerName='System.Data.SqlClient' />", connString); ensureConnectionString.Sequence = 1; ensureConnectionString.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode; webService.WebConfigModifications.Add(ensureConnectionString); webService.Update(); webService.ApplyWebConfigModifications(); }
I wasn't sure if I needed to set the Value when creating the connectionStrings section. The example didn't have it set. I tried a few different things there and nothing worked.
Any ideas on where to check next or how to find out more information?