views:

122

answers:

4

Seems like a fairly straightforward problem. I want to look through about 6gb of content and classic asp code and find anything that looks like a connection string. Problem is, the connection strings are formatted in a dozen different ways.

I was thinking of using a regex to look for specific properties like "catalog=" or "password=" etc. Any thoughts/ideas?

+1  A: 

I feel your pain - why do people DO that??

regex/grep-like tools are the way to go. Accomodating the myriad ways they're formatted won't be fun.

n8wrl
+2  A: 

Cant you use this regex?

@"^([^=;]+=[^=;]*)(;[^=;]+=[^=;]*)*;?$"

http://social.msdn.microsoft.com/Forums/en-US/regexp/thread/48bf2a4f-7312-4a32-b874-b77a27f7c5d0

Shoban
Thats a good regex to use, but it only validates if I'm passing it just a connection string. I need to pass an entire file of text.
oooh ;-) Good luck! Let me see if I can come up with something.
Shoban
A: 

I'd take make a sample file with some random text in it, as well as one connection string in each of your possible formats. Then write (one or many) regexes to that match every connection string in your test file. Then run it on your 6GB of data and hope for the best.

Nate Bross
A: 

being that connection string can be built as just a string:

x = "Provider=xyz;Initial Catalog=bdf;Database=pdq;"

a bunch of continuing lines:

x = "Provider=xyz;" & _
    "Initial Catalog=bdf;" & _
    "Database=pdq;"

a bunch of lines:

x = "Provider=xyz;"
x = x & "Initial Catalog=bdf;"
x = x & "Database=pdq;"

or in dotnet a ConnectionBuilder object

SqlConnectionStringBuilder x = newSqlConnectionStringBuilder();
x.Add("Data Source", "pdq");
x.Add("Initial Catalog", "xyz");

So wouldn't it be better to identify all the places connection strings are used and work backwards?

"sqlconnection|odbcconnect|oledbconnection|connectionstring"

brad.v
Maybe. Problem then is how do you identify all the places the strings are used? This is foreign code to me, and the shear volume of files makes manual processes impossible.