Asp.net odbcCommand not closing connection to mySql

Hi everyone,

i share my pics and my problem: https://imgur.com/a/poes3vI

I have a loop (pic2) in which i need read the some data link to my id….

However… the function works but during longer loops after a while it return as too many connection; in clients connection page (pic1) i saw that the previous query weren’t disposed but i think my code (pic 3-4) is correct…

my co-worker suggested me to read it in one query through inner join, but i prefer to find another way for 2 reason:

  • my way of code is to make a query and load the records as custom class in a list and i would have to navigate directly in datatable and it’ll be messy
    -i have to read external data for a lot of field and one-shot query will be messy and hard to manage for other people

any idea? thk for reading

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

God that’s old school =) You’re not closing the data reader. Also please use using to avoid this eye sore. You can find a textbook example at https://docs.microsoft.com/en-us/dotnet/api/system.data.odbc.odbcdatareader?view=dotnet-plat-ext-5.0 .


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x