473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 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 1509
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

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

Similar topics

4
by: Jason Clark | last post by:
IE says there is a page error. How to rectify? www.beamlmheavyhitter.com Jason
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
3
by: srikanth123456 | last post by:
hi when i am compiling my serial port programmming on windows environment i got a error called "unable to include the header file rs_lib.h. #include"rs_lib.h"
1
by: karthi84 | last post by:
hi, when i tried to open a new excel spread sheet from my web form i got this access denied page. can any one help me in solving this problem. Server Error in '/sk/ContractInvoice'...
2
by: anuparvathy | last post by:
Hi i wanted to resize my cell width of each cell in the grid view.i gave the following code: protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { ...
1
by: Nithya Kalyani | last post by:
Hi Expert, I m a student, can any one help me in finding the answer of below one. The C programs given below contain errors, rectify them as needed. a) void main() { char linebuf; char...
1
by: cmrhema | last post by:
Hi, I want to retrieve the values from store_geofence table where the timeduration exceeds certain interval the procedure is as below CREATE procedure . @regno nvarchar(50), @frmdate...
3
by: sreegans | last post by:
Hi.. i appended 4 to 5 records, after that overflow error had occured while executing the sql query in vb.... Pl guide me how to solve this? Sree...
9
by: ahilar12 | last post by:
1. <head> 2. <script type="text/javascript"> 3. </script> 4. </head> 5. <body> 6. <form> 7. <select name="team" id="mylist" > 8. <option></option> 9....
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.