Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1049
  • Last Modified:

vb6 - I want to use sqlconfigdatasource() to create an oracle odbc datasource

In vb6, I want to create an executable that will in turn create an oracle odbc datasource using sqlconfigdatasource or what ever function is available to do this.
0
tf842
Asked:
tf842
1 Solution
 
tf842Author Commented:
I figured it out:

Option Explicit
Option Compare Text

'Mesages or not
'Public Const SHOW_MSGS_TO_USER = "YES"
Public Const SHOW_MSGS_TO_USER = "NO"

'WIN Authentication
Public Const SQL_TRUSTED_CONNECTION = "YES"
Public Const AUTH_TYPE = "Win"

'SQL Authentication
'Public Const SQL_TRUSTED_CONNECTION = "NO"
'Public Const AUTH_TYPE = "SQL"

'Note: Save the exe with
'  _wa for Windows Authentication (Trusted Connection = "YES"
'  _sqla for Windows Authentication (Trusted Connection = "NO"

'API Constants
Private Const SQL_SUCCESS As Long = 0
Private Const SQL_FETCH_NEXT As Long = 1
Private Const ODBC_ADD_DSN As Long = 1 'Add data source
Private Const ODBC_CONFIG_DSN As Long = 2 'Configure (edit) data source
Private Const ODBC_REMOVE_DSN As Long = 3 'Remove data source
Private Const ODBC_ADD_SYS_DSN As Long = 4 'add a system DSN
Private Const ODBC_CONFIG_SYS_DSN As Long = 5 'Configure a system DSN
Private Const ODBC_REMOVE_SYS_DSN As Long = 6 'remove a system DSN
Private Const ODBC_REMOVE_DEFAULT_DSN As Long = 7 'remove the default DSN
Private Const vbAPINull As Long = 0&  ' NULL Pointer

Public Const SQL_NULL_HANDLE = 0
Public Declare Function SQLConfigDataSource Lib "odbccp32.dll" (ByVal hdbc As Long, ByVal hwnd As Long, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Integer
*****************************
Sub Main()
On Error GoTo NormalErr

  Call ProcessDSNs

NormalErr:
End Sub

*****************************
Private Sub ProcessDSNs()
Dim sServerName As String
Dim sDriverName As String
Dim sDataBase As String
Dim sDescription As String
Dim sSpecialDescription As String

'EDWPRO
  sServerName = "MyOraSrvr"

  sDriverName = "MY_Ora_Srvr"
  sSpecialDescription = "Prod "
  sDescription = sDataBase & " DB " & sSpecialDescription & sServerName
  Call CreateOracleODBCDataSource(sServerName, sDriverName, sDescription)
'
End Sub
*****************************
Private Sub CreateOracleODBCDataSource(sServerName As String, sDriverName As String, sDescription As String)
Dim iRet As Integer
Dim henv As Long

Dim sODBCDriver As String
Dim sAttributes As String

    On Error GoTo CreateDSNErr

    ' All attributes are null-byte terminated, with a double-null at the end!
    'sODBCDriver = "Microsoft ODBC for Oracle"
    sODBCDriver = "Oracle ODBC Driver"

    sAttributes = "DSN=" & sDriverName & Chr(0) & _
    "Description=" & sDescription & Chr(0) & _
    "OemToAnsi=No" & Chr(0) & _
    "DBQ=" & sServerName & Chr(0) & Chr(0) '*********Must be DBQ instead of Server if not SQL Server

'    "Server=" & sServerName & Chr(0) & Chr(0)
   
    ' Create the data source. Using the "ODBC_ADD_SYS_DSN" constant ensures that
    ' it will be a "System" DSN and not a "User" DSN.
    '
    iRet = SQLConfigDataSource(SQL_NULL_HANDLE, ODBC_ADD_SYS_DSN, sODBCDriver, sAttributes)
   
    If (iRet <> False) Then
        MsgBox sDriverName & " ODBC driver installed", vbInformation, "NOTE:"
    Else
        MsgBox "Unable to install " & sDriverName & " ODBC driver", vbExclamation, "ERROR!"
    End If

    GoTo NormalEnd

CreateDSNErr:     ' Error creating data source
    MsgBox Err.Description, vbExclamation, "Creating Data Source"
   
NormalEnd:
End Sub






0
 
GhostModCommented:
Closed, 500 points refunded.
GhostMod
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now