How To Rectify this Error in vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keerthikarani
    New Member
    • Mar 2008
    • 1

    How To Rectify this Error in vb.net

    hi,

    I m using the following code in vb.net, but it shows me some error, can u explain why this error occurs and how to rectify it, but the following code works fine in vb

    Private Declare Function SQLDataSources Lib "odbc32.dll " _
    (ByVal hEnv As Long, _
    ByVal fDirection As Integer, _
    ByVal szDSN As String, _
    ByVal cbDSNMax As Integer, _
    ByVal pcbDSN As Integer, _
    ByVal szDescription As String, _
    ByVal cbDescriptionMa x As Integer, _
    ByVal pcbDescription As Integer) As Long

    Private Declare Auto Function SQLAllocHandle Lib "odbc32.dll " _
    (ByVal HandleType As Integer, _
    ByVal InputHandle As Long, _
    ByVal OutputHandlePtr As Long) As Long

    Private Declare Function SQLSetEnvAttr Lib "odbc32.dll " _
    (ByVal EnvironmentHand le As Long, _
    ByVal dwAttribute As Long, _
    ByVal ValuePtr As Long, _
    ByVal StringLen As Long) As Long

    Private Declare Function SQLFreeHandle Lib "odbc32.dll " _
    (ByVal HandleType As Integer, _
    ByVal Handle As Long) As Long

    Private Const SQL_MAX_DSN_LEN GTH As Long = 32
    Private Const SQL_MAX_DESC_LE NGTH As Long = 128
    Private Const SQL_SUCCESS As Long = 0
    Private Const SQL_FETCH_NEXT As Long = 1
    Private Const SQL_NULL_HANDLE As Long = 0
    Private Const SQL_HANDLE_ENV As Long = 1
    Private Const SQL_ATTR_ODBC_V ERSION As Long = 200
    Private Const SQL_OV_ODBC3 As Long = 3
    Private Const SQL_IS_INTEGER As Long = (-6)


    '//This will list both User and System DSN of local machine
    Private Sub GetDSNList()

    Dim hEnv As Long 'handle to the environment
    Dim sServer As String
    Dim sDriver As String
    Dim nSvrLen As Integer
    Dim nDvrLen As Integer
    Dim a As Long

    Me.WindowState = FormWindowState .Maximized
    Me.AutoSize = True

    'obtain a handle to the environment
    a = SQLAllocHandle( SQL_HANDLE_ENV, _
    SQL_NULL_HANDLE , hEnv)
    If a <> 0 Then

    'if successful, set the
    'environment for subsequent calls
    If SQLSetEnvAttr(h Env, _
    SQL_ATTR_ODBC_V ERSION, _
    SQL_OV_ODBC3, _
    SQL_IS_INTEGER) <> 0 Then


    'set up the strings for the call
    sServer = Space$(SQL_MAX_ DSN_LENGTH)
    sDriver = Space$(SQL_MAX_ DESC_LENGTH)

    'load the DSN names
    Do While SQLDataSources( hEnv, _
    SQL_FETCH_NEXT, _
    sServer, _
    SQL_MAX_DSN_LEN GTH, _
    nSvrLen, _
    sDriver, _
    SQL_MAX_DESC_LE NGTH, _
    nDvrLen) = SQL_SUCCESS


    Me.Show("DSN Name :" & Strings.Left(sS erver, nSvrLen))
    Me.Show("Driver Name :" & Strings.Left(sD river, nDvrLen))
    Me.Show(String. Format(100, "-"))

    Debug.Print("DS N Name :" & Strings.Left(sS erver, nSvrLen))
    Debug.Print("Dr iver Name :" & Strings.Left(sD river, nDvrLen))
    Debug.Print(Str ing.Format(100, "-"))
    MsgBox("mid element" & UCase(Mid(sDriv er, 11, 6)))

    ' If UCase(Mid(sDriv er, 11, 6)) = "ACCESS" Then
    'Combo1.AddItem (sServer)
    'E'nd If
    'repad the strings
    sServer = Space$(SQL_MAX_ DSN_LENGTH)
    sDriver = Space$(SQL_MAX_ DESC_LENGTH)
    Loop
    End If

    'clean up
    Call SQLFreeHandle(S QL_HANDLE_ENV, hEnv)
    End If


    Error occured for this code is follows,
    A call to PInvoke function 'dbfsql!dbfsql. Form1::SQLAlloc Handle' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

    Please reply me soon, with a correct rectified code
  • sd1978
    New Member
    • Jun 2007
    • 5

    #2
    Hi Dear,
    I wont give u the rectified code, that you will have to do on your own.
    I will give a hint.
    Check the DataTypes of the parameters that you are passing in other functions.
    Regards.

    Comment

    Working...