Member Login

Username
Password
Forget Password
New Sign Up
Search Forum

Buy Support
Incidents

If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:

Click Here
If you can't login and post questions or you are having trouble viewing forum posts:
Click Here
Callback
Support

If you live in USA, UK, Canada, Australia or New Zealand, you can leave us details on your question and request us to call you back and discuss them with you personally  (charges apply).

Click Here
 
Buy Support
Incidents
If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:
Click Here

Forum : Attempted to read or write protected memorySearch Forum

Forum Home > FlexODBC - ODBC Driver for DataFlex Embedded DBMS > FlexODBC Bug Reports

 New Topic 
 
 Post Reply 
[1]  
 Attempted to read or write protected memory 
 Author   Message 
  Peter 
  
 Group: Members 
 Posts: 2 
 Joined: 2006-08-28 
 Profile
 Posted : 2006-08-28 17:10:58

I am using ODBC v4 with a .NET application I have written.  

If I run the code below once, then I have no problem. But if I was to run it over and over (by clicking the button to trigger this event), the after a random number of times, I get the following error.

“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”

This can occur after only running it three times in succession and at other times more. This problem still occurs after the application is closed and re-opened. If I was to wait some seconds (say 30) between activating each event, then I can get it to execute more times before recewiving this error message.

Sample Code

Imports ADODB

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim con As New ADODB.Connection
            Dim rs As New ADODB.Recordset
            Dim sql As String = "DELETE FROM DRST WHERE Reference='31460'"

            con.Open("Data source=imsapps")

            With rs
                .CursorType = CursorTypeEnum.adOpenDynamic
                .LockType = LockTypeEnum.adLockOptimistic
                .CursorLocation = CursorLocationEnum.adUseServer
            End With

            rs.Open(sql, con)

            If rs.State = 1 Then
                rs.Close()
            End If

            con.Close()

            rs = Nothing
            con = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-08-29 09:05:21

Are you using FlexODBC v4.0.24 here? The CursorType should only be forward-only not dynamic:

CursorType = adOpenForwardOnly

You should also test whether you have an active connection and use it:

Try ' for opening connection to DataFlex
            If (msodbcConnection Is Nothing) Then
                msodbcConnection = New OdbcConnection
            End If
            If (msodbcConnection.ConnectionString <> "DSN=" & "DataFlex Data32") Then
                msodbcConnection.Close()
                msodbcConnection.ConnectionString = "DSN=" & "DataFlex Data32"
                msodbcConnection.Open()
            End If
            Get_DFConnection = True
            Exit Function
        Catch ex As Exception
            'MsgBox("Invalid DSN Name: " & Err.Description)
            m_streamWriter.BaseStream.Seek(0, SeekOrigin.End)
            m_streamWriter.WriteLine(" DataFlex Database error " & ex.ToString & Constants.vbLf)
            m_streamWriter.Flush()
            m_streamWriter.Close()
            Get_DFConnection = False
            Exit Function
        End Try

instead of starting multiple connections.

 

  Top 
  Peter 
  
 Group: Members 
 Posts: 2 
 Joined: 2006-08-28 
 Profile
 Posted : 2006-08-29 12:03:56

Hello Tom,

Thank you for your post. I have implemeted your suggestions and still get the same error message. Here is a copy of my test program.

Imports ADODB

Public Class Form1

    Private Con As New ADODB.Connection

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim rs As New ADODB.Recordset
            Dim sql As String = "DELETE FROM DRST WHERE Reference='31460'"

            If Not TestConnection(Con) Then
                MsgBox("Could not establish a connection")
            End If

            With rs
                .CursorType = CursorTypeEnum.adOpenForwardOnly
                .LockType = LockTypeEnum.adLockOptimistic
                .CursorLocation = CursorLocationEnum.adUseServer
            End With

            rs.Open(sql, con)

            If rs.State = 1 Then
                rs.Close()
            End If

            rs = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave
        Con.Close()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Con.ConnectionString = "Data source=imsapps"
        Con.Open()
    End Sub

    Private Function TestConnection(ByRef Connection As ADODB.Connection) As Boolean
        Try ' for opening connection to DataFlex

            If (Connection Is Nothing) Then
                Connection = New ADODB.Connection
            End If

            If Connection.ConnectionString <> "DSN=imsapps" Then
                If Connection.State <> 0 Then
                    Connection.Close()
                End If
                Connection.ConnectionString = "DSN=imsapps"
                Connection.Open()
            End If

            TestConnection = True
        Catch ex As Exception
            MsgBox("Invalid DSN Name: " & ex.Message)
            TestConnection = False
        End Try
    End Function
End Class

 

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-08-29 14:03:02
This problem has been escalated to Level 2 Support with the FlexODBC Software Engineer under Ticket ID: DF00000002. No resolution time frame is available for FlexODBC bug fixes. 

  Top 
 New Topic 
 
 Post Reply 
[1]  

Jump to