Using Regular Expressions (Regex) to find all your SqlConnection strings

I was looking through some inherited code and there were some connection strings spread out throughout the project. Now because I try to make sure everything is closed in good order I needed a way to find where each was declared. I could change them all to using Statements but that just seems like a lot of work.

Instead, I found this nifty little piece of regex syntax that allows you to search through your connection strings:


In Visual Studio 2010 hit Ctrl+F and place the string in the Find what: textbox of the Find and Replace dialog box. Make sure to click the Use checkbox at the bottom and select Regular expressions. Also, make sure there are no trailing spaces after the last bracket or else it will not work. Click Find Next and voila. The nice thing about this is that it will find them if they are declared explicitly or not.

Find SQlConnection string with regex


About Ken Cenerelli
I am a technical writer/programmer writer/content developer, .NET developer, Microsoft MVP, public speaker, blogger, and Microsoft Azure nerd. I blog about technology at and am on Twitter via @KenCenerelli.

One Response to Using Regular Expressions (Regex) to find all your SqlConnection strings

  1. Pingback: Using Statements to wrap your database connections « Ken Cenerelli

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: