Solved

ODBC 3.0 and VB

Posted on 1997-06-01
2
307 Views
Last Modified: 2006-11-17
Trying to use ODBC 3.0 with VB4, unfortunately all examples in ODBC 3.0 SDK are in C language, any idea
from where I can get VB examples on a Internet, can you
write at least SQL AllocHandle part for me in VB.
Thank a million
Matthew
0
Comment
Question by:mativare
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
markbob061097 earned 50 total points
ID: 1426685
The following is what I use to connect to an ODBC database.  You must supply the values for the gsDataSource (ODBC Datasource), gsUserID (Database UserID), and gsPassword (Database password) variables.  If the fODBCConnect returns a 0 then it connected to the database correctly.

A book that has a chapter on ODBC programming in Visual Basic which I learned from is "Teach Yourself Database Programming with Visual Basic 4" from SAMS Publishing.

' 32-bit ODBC API Declares (Remove 32 from dll for 16-bit systems)
  Declare Function SQLAllocEnv Lib "odbc32.dll" (env As Long) As Integer
  Declare Function SQLAllocConnect Lib "odbc32.dll" (ByVal env As Long, hdbc As Long) As Integer
  Declare Function SQLAllocStmt Lib "odbc32.dll" (ByVal hdbc As Long, hstmt As Long) As Integer
  Declare Function SQLConnect Lib "odbc32.dll" (ByVal hdbc As Long, ByVal Server As String, ByVal serverlen As Integer, ByVal uid As      String, ByVal uidlen As Integer, ByVal pwd As String, ByVal pwdlen As Integer) As Integer

' SQL/ODBC Constants
  Public Const SQL_SUCCESS = 0
  Public Const SQL_NO_DATA_FOUND = 100

' ODBC Variables
  Public glHenv As Long           ' Environment Handle
  Public glHdbc As Long           ' Database Connection
  Public glHstmt As Long          ' Statement Handle
  Public gsDataSource As String   ' Data Source Name (You Provide Value)
  Public gsUserID As String       ' User ID (You Provide Value)
  Public gsPassword As String     ' User Password (You Provide Value)

Public Function fODBCConnect() As Integer

    ' Declare Variables
        Dim nResult As Integer

    ' Get Environment Handle
        nResult = SQLAllocEnv(glHenv)
    If nResult = SQL_SUCCESS Then
    ' Get Connection Handle
        nResult = SQLAllocConnect(glHenv, glHdbc)
    If nResult = SQL_SUCCESS Then
    ' Connect to Database
        nResult = SQLConnect(glHdbc, gsDataSource, Len(gsDataSource), gsUserID, Len(gsUserID), gsPassword, Len(gsPassword))
    If nResult = SQL_SUCCESS Then
    ' Get Statement Handle
        nResult = SQLAllocStmt(glHdbc, glHstmt)
    End If
    End If
    End If

    ' Set Return Value
        fODBCConnect = nResult

End Function
0
 
LVL 1

Author Comment

by:mativare
ID: 1426686
Response excelent, but still in your sample ODBC 2,0 used
I was looking for ODBC 3.0 sample. It all begins with
SQLAllocHandle(), SQlAllocEnv() is obsolete in ODBC 3.0
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question