Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mysql  maximum connection error

Posted on 2009-07-10
7
Medium Priority
?
270 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 2000 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 2000 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

610 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