Solved

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

Posted on 2006-06-29
2
1,016 Views
Last Modified: 2008-01-09
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
Comment
Question by:tf842
2 Comments
 

Author Comment

by:tf842
ID: 17011325
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
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 17021589
Closed, 500 points refunded.
GhostMod
Community Support Moderator
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

786 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