Public Function Call (System.StackOverflowException)

G

Guest

in frmRoutines (Form3) I have a working public function called getLog()

I attempt to call it in frmMIS (Form2) as follows and get the above
exception...
....
Dim frmMISRoutine As New Routines
frmMISRoutine.getLog()
....
What are my options to avoid rewriting the getLog function again in Form2?

Marc
 
M

Marina

The problem is the code in your function. You are not showing us what it
does, but likely it is calling itself recursively, and never actually stops.
 
G

Guest

Hi,

I have just posted a thread above which explains what I really want to do
but this is still an issue too. Here is my function to call

Public Function getLog()

Dim LogtoSet As New ArrayList

For Each Item As Object In ChkListBoxRoutines.Items
LogtoSet.Add(Item)
Next

For Each Item As Object In LogtoSet

Dim strSQL As String = "SELECT TOP 1 id, log_desc FROM
MISRE_dss_log WHERE LogStat = 'Y' "
Dim cmdSelect As New SqlClient.SqlCommand
cmdSelect.CommandText = strSQL
cmdSelect.CommandType = CommandType.Text

Try
cn = New SqlClient.SqlConnection("user id=" & UserName.Text
& ";password=" & Password.Text & ";database=" & Database.Text & ";server=" &
Server.Text)
cn.Open()
cmdSelect.Connection = cn
Catch ex As Exception
sqlCnError = ("Error: Could not establish database
connection")
End Try

dtr = cmdSelect.ExecuteReader(CommandBehavior.SingleRow)

If (dtr.Read()) Then
If Not dtr.IsDBNull(0) Then
logid = dtr.GetInt32(0)
logdesc = dtr.GetString(1)
'logroutine = dtr.GetString(2)

frmMIS.LogBox.Text &= logdesc + ControlChars.CrLf + ""

Dim strSQL1 As String = "UPDATE MISRE_dss_log SET
logStat = 'N' WHERE id = '" + logid + "' "
Dim cmdSelect1 As New SqlClient.SqlCommand
cmdSelect1.CommandText = strSQL1
cmdSelect1.CommandType = CommandType.Text

Try
cn = New SqlClient.SqlConnection("user id=" &
UserName.Text & ";password=" & Password.Text & ";database=" & Database.Text &
";server=" & Server.Text)
cn.Open()
cmdSelect1.Connection = cn
cmdSelect1.ExecuteNonQuery()
Catch ex As Exception
sqlCnError = ("Error: Could not establish database
connection")
End Try
End If
End If

dtr.Close()
cn.Close()
cn.Dispose()
Next
End Function
 
M

Marina

What event are you calling getLog from?

In general though, to solve these kinds of issues you should just debug the
code, and see what is causing the function to get called over and over.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top