Solved

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

Posted on 2006-06-29
2
1,007 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
Comment Utility
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
Comment Utility
Closed, 500 points refunded.
GhostMod
Community Support Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now