I wrote code that searches an XML document for patterns (using Regex) of the form #<variable-name>#, and then substitutes the right value for <variable-name> by querying an SQL database.
To do the substitutions, I'm using Regex.Replace() with a MatchEvaluator function.
My problem is, MatchEvaluator is a static function, so it can't access the class's existing non-static SqlConnection to query the database. If I make the SqlConnection static, it becomes non-thread-safe. For efficiency reasons, I don't want to open a new SqlConnection every time I call MatchEvaluator. Is there any way to do this?