Solved

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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Title # Comments Views Activity
SSRS expression Issue finding a string 10 89
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 54
Automatic Email Reminder 4 56
which modules are active in VB6 project? 6 39
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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

809 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