Solved

mysql  maximum connection error

Posted on 2009-07-10
7
257 Views
Last Modified: 2012-05-07
Here is my sample connection code and error why it is not closing connection and i always clean them manually? This is workin on webservice
Dim cn As New MySqlConnection
        cn.ConnectionString = ConfigurationSettings.AppSettings("ConnectionString")
        Dim dr As MySqlDataReader
        Dim cmd As New MySqlCommand(sql.resimler, cn)
        cmd.Parameters.Add("?bolum", bolum).MySqlDbType = MySqlDbType.VarChar
        cmd.Parameters.Add("?bolumno", bolumno).MySqlDbType = MySqlDbType.VarChar
        cn.Open()
        dr = cmd.ExecuteReader
        Dim resim = ""
        If dr.Read = False Then
            Return "Yok,"
        Else
            resim += dr.Item(2) & ","
            While dr.Read()
                resim += dr.Item(2) & ","
            End While
        End If
        Return Left(resim, Len(resim) - 1)
        dr.Close()
        cn.Close()

Open in new window

hatamysql.jpg
0
Comment
Question by:CahitEy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 24825941
You are returning before the close of the dr and cn objects.  Set your return value to a variable and return it at the very end instead.
0
 
LVL 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 500 total points
ID: 24826075
More like this:
Dim returnVal As String = "Yok"
 
Using cn As New MySqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
	Using dr As MySqlDataReader
		Dim cmd As New MySqlCommand(sql.resimler, cn)
		cmd.Parameters.Add("?bolum", bolum).MySqlDbType = MySqlDbType.VarChar
		cmd.Parameters.Add("?bolumno", bolumno).MySqlDbType = MySqlDbType.VarChar
		
		cn.Open()
		dr = cmd.ExecuteReader
		
		If dr.Read Then
			returnVal = dr.Item(2)
			
			While dr.Read()
				returnVal &= "," & dr.Item(2)
			End While
		End If
		
		dr.Close()
	End Using
	
	cn.Close()
End Using
 
Return returnVal

Open in new window

0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 24826084
The using statements should take care of both close() and dispose() of the objects also...
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 1

Author Comment

by:CahitEy
ID: 24826097
Thanks for both answers it is ok now , the both answer is the solution
0
 
LVL 1

Author Comment

by:CahitEy
ID: 24826107
i made point 500 to give 250 for each answer thanks again
0
 
LVL 1

Author Closing Comment

by:CahitEy
ID: 31602206
Thanks
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 24826121
CahitEy,

You are most welcome.

Thank you very much for the points.

Happy coding!

Regards,
Kevin
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS SQL Update query with connected table data 3 65
Need syntax help building hyperlink 2 42
Running powershell scripts from ASP.NET 6 60
MySQL Persistent Connections 10 36
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question