Solved

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

Posted on 2006-06-29
2
1,023 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
[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
 

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

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!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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