1

Is there a way to find out which parts of my different websites are connected to which SQL databases and/or tables? (database and websites were not built by me)

I want to know that page "whatever.aspx" is connected to the SQL instance "dbo.Whatever". Is there a way to do that?

Mr_Thomas
  • 857
  • 3
  • 19
  • 39

2 Answers2

0

I think that it's going to depend a lot on how the pages were coded. Is there a middle tier?

You can use SQL Profiler to capture connections to the database, but whether or not there will be any information there to allow you to distinguish pages will depend on how they were coded.

Likewise, assuming that you have a code base of the various web sites you should be able to do a search through those, but again it depends on how they were coded.

Tom H
  • 46,766
  • 14
  • 87
  • 128
  • No, I mean whether or not you've set certain properties (for example, the SQL Profiler tracks the "application name" of the connection. WHen using .NET that defaults to something like "Microsoft .NET", but in your code you can change that. Very few developers actually do. If you have a middle tier that can further obfuscate things. For example, if the pages are using web services that are in turn connecting to your database. – Tom H Jul 20 '11 at 14:48
  • I'm not a developer or anything but I can (sort of) read the ASPX file. Is there something in there that will help me answer your question? Meaning: what in the file will tell me the 'application name'? – Mr_Thomas Jul 20 '11 at 14:52
0

There are two ways I can think of doing this:

  1. If you have a list of tables names from your database you can search your .aspx or corresponding .aspx.cs code for references them. This will tell you which database a web page is using.
  2. You can also search for connection strings in your web.config file and then find references to those connection string in your .aspx or corresponding .aspx.cs pages.

Note: Every page in your .aspx or corresponding .aspx.cs code that connects to a database must use a connection string (or a reference to a connection string in the web.config). It might be time consuming but you can build a map of which pages connect to which databases by looking for references to tables or connection strings.

Chris
  • 1,038
  • 18
  • 23
  • Okay, I think you're getting me closer to the answer. I found a database called STANDARD which has a database named "dbo.Contacts". Then I found two files called "contacts.aspx" and "contacts.aspx.cs". None of these files (nor the web.config file) refer to any of these names. There must be something in the middle that I'm not seeing? – Mr_Thomas Jul 20 '11 at 16:23
  • I think the item "dbo.Contacts" you're referring to is a table. Which is probably a member of the database STANDARD. You should be looking at the text inside your .aspx and .aspx.cs files for references to ".dbo.Contacts" and STANDARD. The names of the files "contacts.aspx" & "contacts.aspx.cs" don't necessarily mean they reference your database, it's what's inside the .aspx and .aspx.cs files that matters. – Chris Jul 20 '11 at 16:36
  • I've searched through the .aspx and .aspx.cs files and I don't see anything that references 'dbo.contacts' or even the word Standard. – Mr_Thomas Jul 20 '11 at 17:40
  • 1
    Next look for a file named "web.config". This file should contain at least one connection string entry. Connection strings are in a format similar to this `` but in place of `Catalog=myDataBase` would be `Catalog=standard` or something similar. If you locate a match in your web.config then you can look for the name of that connection string (from `name=ConnectionStringName` in your web.config) in your .aspx and .aspx.cs files. – Chris Jul 20 '11 at 18:12
  • Could that BE any more convoluted? I don't think so... You did answer my question so, thank you. – Mr_Thomas Jul 20 '11 at 18:29