Find Connection Object

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
 
R

Robert Porter

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
 
T

Tom W

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
 
S

Steve Drake

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top