PInvoke Error when calling API odbc32.SQLGetData function

Runtime error generated by PInvoke when passing contol over to unmanag

Page 1 of 1

0 Replies - 2678 Views - Last Post: 20 November 2007 - 06:50 PM Rate Topic: -----

#1 soorugdee   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-November 07

PInvoke Error when calling API odbc32.SQLGetData function

Post icon  Posted 20 November 2007 - 06:50 PM

Error Generated
The runtime has encountered a fatal error. The address of the error was at 0x79e95b95, on thread 0xdfc. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

Code where the error occurs

Have been using the ODBC32.dll to connect to a sql server and prior to this error the following has been achieved -
1 SQLHandle has been created for the environment , connection and SQL statements and this has returned SQLSUCCESS. The error happens when an SQLGetData is executed - this is so piecemeal data can be retrieved without having to bind to specific data types and image or long text can be retrieved successively.
I have tried trapping the exception error using Try Catch but the error keeps returning then a AccessViolation exception.
How would you possibly find the erngine error when it keeps returning another error on top of the another ????

Please help !

The follwing code comes a function

The library definitions for SQLGetData
Private Declare Function SQLGetData Lib "odbc32.dll" (ByVal hstmt As Int32, ByVal icol As UInt16, ByVal fCType%, ByRef rgbValue() As Byte, ByVal cbValueMax As Int32, ByRef pcbValue As Int32) As Int32

Public Function SQLColVal(ByVal SQLColNum As Integer) As String
'Return the data in the current row of the current result set corresponding to column SqlColNum.
'Function returns "" for any error.

Const MAX_DATALEN As Int32 = 8000 'max length of non-text/image data for SQL Version 7 and up

'Dim svalue As String * MAX_DATALEN no longer supported in VB.NET
'Dim svalue As New StringBuilder("0", MAX_DATALEN)
Dim nreturned As Int32
Dim result As Int32

Dim temp_str As String = ""
Dim datatypename As String 'name of type of data returned
Dim svalue As Object

'svalue = Space(MAX_DATALEN)
SQLColVal = "" 'default
datatypename = get_SQL_ColDataType_name(SQLColNum)
Select Case datatypename
Case "image", "text"
If SQL_sreadblob(SQLColNum, datatypename, temp_str) = SQL_SUCCESS Then SQLColVal = temp_str
Exit Function
Case "" 'oops
Exit Function
Case Else
End Select

result = SQLGetData(hstmt, SQLColNum, SQL_C_CHAR, svalue, MAX_DATALEN, nreturned) <<---- this is where the fatal execution engine error occurs

' result = SQLGetData(hstmt, SQLColNum, SQL_C_CHAR, svalue, MAX_DATALEN, nreturned)
' Catch exc1 As System.AccessViolationException
' MsgBox("error" & exc1.Message)
' End Try

If (result = SQL_SUCCESS) And (nreturned > 0) Then
temp_str = Trim$(Left$(svalue(1), nreturned))
If InStr(1, temp_str, ".") Then 'check if column of money type
If InStr(1, datatypename, "money", 1) Then temp_str = Format$(temp_str, "########0.00")
End If
If sql_dateformat <> "" And InStr(1, datatypename, "datetime", 1) > 0 Then '(9)
If Right$(temp_str, 4) = ".000" Then temp_str = Left$(temp_str, Len(temp_str) - 4) '!!!AAARRRGGGHHH strip milliseconds (maybe)
temp_str = Format$(temp_str, sql_dateformat)
End If
If result <> SQL_SUCCESS Then
Debug.Print("SQLColVal(" & Trim$(SQLColNum) & ") failed.")
End If
temp_str = ""
End If
SQLColVal = temp_str
End Function

Is This A Good Question/Topic? 0
  • +

Page 1 of 1