Best Practises Question: SqlConnection or ConnectionString

M

Mark Redman

Hi All,

In our ASP.NET applications we use a connection string to connect to the
database, this obviously makes sense as the client(web browser) is
discinnected from the server and requests can be made at any time.

In the past when I programmed in Delphi and used ADO for windows
applications, I always created a database connection object which I used for
all database connectivity.

I am busy with a C# winforms application and cant decide if I should use a
connection string when making calls or use an SqlConnection object each
time, which gets created when the app runs.

(Obviously transactions can get created by either the connection string or
connection, but I am talking about single calls)

Any comments on this would be appreciated.

Thanks

Mark Redman
 
J

Joyjit Mukherjee

Hi,

Sql Connection objects are automatically served from and created in the
pool, if not disabled otherwise. So each time you request for such an
object, it is served from the pool if already available, or created, served
to you, and kept in the pool for further use.

Hope that solves your query.

Regards
Joyjit
 
C

Cor Ligthert

Mark,

Best practise is to open a connection when it is needed and dispose when it
is not anymore needed. What object or connection string you use for that is
not important as long that it is at least a not an already used connection
for every to open connection.

Know that the dataadapter can do this automaticly for you what is advices
when you use one fill at a time.

I hope this helps?

Cor
 

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