472,958 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How To Rectify this Error in vb.net


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, _
If a <> 0 Then

'if successful, set the
'environment for subsequent calls
If SQLSetEnvAttr(hEnv, _

'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, _
sServer, _
nSvrLen, _
sDriver, _

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
'E'nd If
'repad the strings
sServer = Space$(SQL_MAX_DSN_LENGTH)
sDriver = Space$(SQL_MAX_DESC_LENGTH)
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 1475
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.
Mar 14 '08 #2

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

Similar topics

by: Jason Clark | last post by:
IE says there is a page error. How to rectify? www.beamlmheavyhitter.com Jason
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
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"
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'...
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) { ...
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...
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...
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...
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....
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.