Identifying underlying sql connection of SqlConnection object?

You could set the application name in the connection string, this is then visible in SQL Server. Normally it is defaulted the the SQL Client, but you can override.

You could set the application name in the connection string, this is then visible in SQL Server. Normally it is defaulted the the SQL Client, but you can override: "Integrated Security=true;Initial Catalog=Northwind;server=(local);Application Name=MyKeyword" This property can be read back by the ConnectionString property of the SqlConnection instance. Edit: As noted by edg the connection string defines which connection pool, so this probably wouldn't work.

Unfortunately this would have the side-effect of changing the pool. (Pools are created per connection string) – Ed Guiness Feb 20 '09 at 14:58.

Not a direct answer, but something you should note. The hash code of an object shouldn't change throughout its lifetime. If it did, then you could put an object into a hashed collection, change it's hash code then then be unable to retrieve it from the collection again.

If you attach a debugger and view the private fields, can't you turn some kind of internal identifier up? If so, you could access that via reflection during your debugging if you had to.

Yup, I understand the immutability of GetHashCode. It's the underlying connection I'm after though, but no idea how to identify it. – Ed Guiness Feb 20 '09 at 14:24.

Richard's answer will not help you, if I am understanding your issue properly, as you are looking for the actual object in the underlying . NET connection pool. I am also not convinced that the hash will help, as you are looking at the underlying pool.

I do not have an answer, per se, but a suggestion. Get a copy of Reflector (now a RedGate product) and go through System.Data. DLL and look at how things are stored in the underlying pool.

I am not sure it will give you a quick and easy answer, but if there is any thing you can reflect on to get an answer to help debug your problem, it is going to be there. BTW, what is the bug you are trying to solve?

One thing you could try is SqlConnection.ClearPool(); or SqlConnection.ClearAllPools(); to see if you can isolate any of the issues you are facing.

Not to say that this is impossible, but I've not yet found any way to do it.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions