Web Config Transformation Syntax
Asked Answered
P

2

10

I've been following the MSDN guide for Web Config Transformation and by-and-large have had success with it.

However, one line of my web config is giving my troubles and I can only assume it's because I'm misunderstanding the guide and using the wrong syntax.

I'm hopeful that someone will be able to point out my mistake, and will be grateful if that's the case.

The offending line in the transform is:

<sessionState sqlConnectionString="data source=localhost;uid=userId;pwd=password;" xdt:Transform="SetAttributes(sqlConnectionString)" />

The line in the original web config is:

<sessionState mode="SQLServer" sqlConnectionString="data source=networkAlias;uid=userId;pwd=password;" cookieless="UseDeviceProfile" timeout="120" />

My hope was that the transform would replace the attribute "sqlConnectionString", changing the connection details. Unfortunately the line is unaffected.

I've used exactly the same syntax for:

<network host="localhost" xdt:Transform="SetAttributes(host)" />

The above works just fine, so I had assumed it would be the case for the too.

Can anyone see where I'm going wrong?

Phene answered 28/10, 2011 at 12:29 Comment(0)
P
4

After taking a break and coming back to it with some fresh eyes, I realised that the syntax was in fact just fine.

The problem was that at some point - no idea when - the element had been moved (maybe a copy/paste error by myself or another team member) out of the element where it belonged, so it was just hanging there and not where it should have been.

Once I moved back into where it should have been, problem solved, the transform was correctly detecting the element again and applying the transform.

So, lesson learned: if a transform is mysteriously not being applied to one element (when it works just fine on another), check to make sure the element is correctly situated.

Phene answered 31/10, 2011 at 16:32 Comment(0)
T
6

Just a simple typo. You need to change sqlConnectionString to stateConnectionString. You have it right in the web.config, but not the transformation. Otherwise, the transform looks good.

You need to change sqlConnectionString here:

<sessionState sqlConnectionString="data source=localhost;uid=userId;pwd=password;" xdt:Transform="SetAttributes(sqlConnectionString)" />

To stateConnectionString:

<sessionState stateConnectionString="data source=localhost;uid=userId;pwd=password;" xdt:Transform="SetAttributes(stateConnectionString)" />
Transudation answered 28/10, 2011 at 12:47 Comment(5)
Apologies, I realised the stateConnectionString line in the config is pointless, as we're running in SQLServer mode, so I removed that. Even still, isn't that just the same as what I've already done? The transform should replace the sqlConnectionString attribute, but it's not, unless I'm being a bit dense.Phene
@Phene In your example you're telling it to replace sqlConnectionString, but sqlConnectionString doesn't exist. Therefore it doesn't do anything. It has to match something to replace it. sqlConnectionString also isn't valid on the sessionState element which could be the reason it's not working.Transudation
According to the MSDN (msdn.microsoft.com/en-us/library/h6bb9cz9(v=VS.100).aspx) sqlConnectionString is a valid attribute, to be used with mode="SQLServer". If mode="StateServer", then it needs the stateConnectionString attribute. How else does one make use of the ASPState databases for storing state, which is what we do currently, we don't run the ASP State service on a server. Also, in my example, the first code snippet is the transform and the second the web config it's being applied too, sqlConnectionString is present, so I'm afraid I don't understand your comment.Phene
Regardless, I tried your suggestion and it had no effect, unfortunately. I was also unable to transform the timeout attribute either, yet have not had this problem with such a simple tranform on other elements, so perhaps my problem is something I've not considered beyond syntax.Phene
Problem solved, just waiting for the time period to elapse so I can answer the question properly. Thanks for your efforts.Phene
P
4

After taking a break and coming back to it with some fresh eyes, I realised that the syntax was in fact just fine.

The problem was that at some point - no idea when - the element had been moved (maybe a copy/paste error by myself or another team member) out of the element where it belonged, so it was just hanging there and not where it should have been.

Once I moved back into where it should have been, problem solved, the transform was correctly detecting the element again and applying the transform.

So, lesson learned: if a transform is mysteriously not being applied to one element (when it works just fine on another), check to make sure the element is correctly situated.

Phene answered 31/10, 2011 at 16:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.