By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,822 Members | 1,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,822 IT Pros & Developers. It's quick & easy.

Public Function Call (System.StackOverflowException)

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
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.

"marcmc" <ma****@discussions.microsoft.com> wrote in message
news:5E**********************************@microsof t.com...
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

Nov 21 '05 #2

P: n/a
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
Nov 21 '05 #3

P: n/a
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.

"marcmc" <ma****@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
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

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.