Link to home
Start Free TrialLog in
Avatar of yizchaknaveh
yizchaknaveh

asked on

Using Regex MatchEvaluators with an SqlConnection

Hi,

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?
SOLUTION
Avatar of NipNFriar_Tuck
NipNFriar_Tuck

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yizchaknaveh
yizchaknaveh

ASKER

Excellent.  Thanks.  I made it non-static and all problems went away.  I'm not sure why I thought it had to be static.