views:

747

answers:

7

I have a third party library that internally constructs and uses the SqlConnection class. I can inherit from the class, but it has a ton of overloads, and so far I have been unable to find the right one. What I'd like is to tack on a parameter to the connection string being used.

Is there a way for me to put a breakpoint in the .NET library core itself? Specifically in the constructors of the SqlConnection class, so that I can look at the stack trace and see where it is actually being constructed?

Barring that, is there some other way I can do this?

Specifically, what I want to do is to tack on the Application Name parameter, so that our application is more easily identified on the server when looking at connections.


Edit: Well, it appears I need more help. I think I've enabled everything related to symbol server support, and I've noticed that the directory I configured has filled up with directories that contain .pdb files. Still, I can't get the actual source to the SqlConnection class to become available.

Is there some definite guide to how to do this successfully?

+6  A: 

You can download .NET source code and set break point right in .NET FW source code.

You can use NetMassDownloader to grab .NET sources quickly.

aku
+3  A: 

According to this article you can download the source code for the .NET framework and then debug it using visual studio:

http://weblogs.asp.net/scottgu/archive/2007/10/03/releasing-the-source-code

Espo
Heh! I'm outrun you this time 8-)
aku
Damn. 2 times in 5 minuttes :) . What is the "best practices" on this sort of thing, should i delete my answer?
Espo
I'm just bored to death today. SO is a great fun!
aku
I will let my answer stay then. Although we both had the same answer, mine has a different link that some day might help someone.
Espo
I think it's fair :)
aku
A: 

Right, of course, now why didn't I think of that...

Lasse V. Karlsen
+2  A: 

And if you can't use source level debugging with the .Net framework source code Microsoft supplied, you could try a different debugger. Like mdbg or even windbg.

edit

This explains getting the released parts of .Net framework and how to set breakpoints in great detail. The NetMassDownloader will give you everything (pdb and source) in one download. But not all source code of the .Net framework is available. If your SqlConnection is not you can always use IL debuggers like the ones I mentioned. And don't forget Lutz's Reflector to give you a look at the source code anyway.

Lars Truijens
+3  A: 

I almost forgot to mention Deblector - it's a Reflector plugin, that allows you to debug almost any .net app without source codes :)

aku
+2  A: 

While source debugging is defintely better, you don't need pdbs or source for the VS debugger to set a bp on the function you want.

Make sure you go to Tools/Options/Debugger and turn off the option called "Just My Code". Since the framework is not 'your code' the debugger unhelpfully prevents you from setting breakpoints there.

Next you need the full name of the method as it appears in the metadata. This includes any namespaces it is nested in. I'd recommend ILDasm or Reflector if you need to find the name.

On the breakpoints window in the upper left corner is a "new bp" menu button. One of the choices is to set a bp on function name. When the dialog comes up uncheck having intellisense check the name since you don't have a project. I hope that helps.

Steve Steiner
How would I add a breakpoint to the constructor of SqlConnection that takes a String?I tried:System.Data.SqlClient.SqlConnection.ctor(string)System.Data.SqlClient.SqlConnection.ctor(string connectionString)... and the same with SqlConnection instead of ctor.
Lasse V. Karlsen
A: 

OK, if you want definitive guide, here it is:

Configuring Visual Studio to Debug .NET Framework Source Code

If you want some help, go ahead and tell use which steps did you perform?

aku