Find Connection Object

  • Thread starter Thread starter Tom W
  • Start date Start date
T

Tom W

How can I locate the currently active database connection? I'm writing a
class that will be used in an application that will have one connection
object. Without passing it the connection, how can I locate it?

Tom
 
You would either have to pass it, or expose it as a public property in
the other assembly.

You could also use reflection but that would be more involved than you
probably want to get into.

Bob
 
How would I get started using reflection?

Tom



Robert said:
You would either have to pass it, or expose it as a public property in
the other assembly.

You could also use reflection but that would be more involved than you
probably want to get into.

Bob
 
I think I understand what you are trying todo here.

with data access from .NET / ADO, you should never try to manage your own
connection pooling, the framework does all this.

Open you connection and close it as soon as possible, the next call will
reuse the connection you just closed, and it will still be ready and open.

if you really do want a static connection, then why not use a static
connection? eg :

public class DBHelper
{
static sqlConnection connection;
public static sqlConnection Connection
{
get
{
// connect here
return this.connection;
}
}
}





Steve
 
Back
Top