471,120 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,120 software developers and data experts.

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 cbDescriptionMax 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 EnvironmentHandle 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_LENGTH As Long = 32
Private Const SQL_MAX_DESC_LENGTH 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_VERSION 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(hEnv, _
SQL_ATTR_ODBC_VERSION, _
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_LENGTH, _
nSvrLen, _
sDriver, _
SQL_MAX_DESC_LENGTH, _
nDvrLen) = SQL_SUCCESS


Me.Show("DSN Name :" & Strings.Left(sServer, nSvrLen))
Me.Show("Driver Name :" & Strings.Left(sDriver, nDvrLen))
Me.Show(String.Format(100, "-"))

Debug.Print("DSN Name :" & Strings.Left(sServer, nSvrLen))
Debug.Print("Driver Name :" & Strings.Left(sDriver, nDvrLen))
Debug.Print(String.Format(100, "-"))
MsgBox("mid element" & UCase(Mid(sDriver, 11, 6)))

' If UCase(Mid(sDriver, 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(SQL_HANDLE_ENV, hEnv)
End If


Error occured for this code is follows,
A call to PInvoke function 'dbfsql!dbfsql.Form1::SQLAllocHandle' 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
Mar 14 '08 #1
1 1355
sd1978
5
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.
Mar 14 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Jason Clark | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.