Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

c# - 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 .


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...