SQLConnection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have few forms that I am trying just to display the data.

In each form I need to fire different sqlstatements to get the data. Before
executing each sql statement I am opening the connection, executing
sqlreader, closing sqlreader and closing the connection. Sometimes I get
errors like SQL connection is already open or sqlcon is busy fetching etc.

What is the better approach for me to accomplish this.

Thanks
 
You might try using the same connection for all the readers - keep the
connection open. Don't close it until all the data retrieval is done.

Make sure the readers run one right after the other...get what data you need
- and then close them right away.

Assuming that you don't have to wait for anything between queries - such as
user events - this should not only work well but make good use of resources,
as well.

HTH
 
Hi,

It seems that you are somewhat leaking your connections.
Are you sure that you are closing them?
Do you use threading?
 
make sure that you are creating a new connection in each form, specifically
I would recomend the "using" statement to avoid leaks.
Using the same connection in multiple threads is not supported.

--
Angel Saenz-Badillos [MS] Managed Providers
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
I am now blogging about ADO.NET: http://weblogs.asp.net/angelsb/
 
Back
Top