handling db connection

Posted by Thiru under VB.NET on 6/2/2012 | Points: 10 | Views : 1407 | Status : [Member] | Replies : 2
Hi friends,

one small doubt.
in a loop i have to check the username availability in database for each id.

in this case: what will be the best practice:

1. open db connection in "check_availability_function" and close db there itself
so, as each & every time when the function call - its will open & close the db connection.

2. Open db connection before loops starts and pass the connection string to required functions...
(without opening & closing connection each time function ececutes)
and finally close the connection after loop ends.




Responses

Posted by: T.Saravanan on: 6/3/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Try Disconnected architecture.....

For ex:


SqlConnection sqlConn = new SqlConnection(.....);
SqlDataAdapter da = new SqlDataAdapter("Select * from table", sqlconn);
DataTable dt = new DataTable();
da.Fill(dt);


Refer the below links for more reference...
http://csharp.net-informations.com/ado.net/ado.net-data-access-architecture.htm
http://www.programcall.com/3/adonet/disconnected-architecture-in-adonet.aspx


Thanks,
T.Saravanan

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/3/2012 [Member] Starter | Points: 25

Up
0
Down
Try Disconnected DataBase Architecture,

Retrieve all data in DataTable and then Make a loop on that Table,

It is better then Access Database all time in loop,
Also it will increase performance of your code.

if need further help? then put comment on this post

Enjoy.......

Ajay
ajaypatelfromsanthal.blogspot.in

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response