Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC Setup?

Status
Not open for further replies.

gieboy

Programmer
Feb 15, 2001
20
PH
I want to make a program that will Setup an ODBC connection.
How can I do this? Need ur help very badly.
Can I use RegisterDatabase method? How?
 
'Constant Declaration
Private Const ODBC_ADD_DSN = 1 ' Add data source
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
Private Const vbAPINull As Long = 0& ' NULL Pointer

'Function Declare
#If Win32 Then

Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) _
As Long
#Else
Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" _
(ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal _
lpszDriver As String, ByVal lpszAttributes As String) As Integer
#End If




'If connection cant open - create the DSN

If gConnect.State <> adStateOpen Then
Beep
MsgBox &quot;Your DSN does not exist&quot;
' #If Win32 Then
' Dim intRet As Long
' #Else
' Dim intRet As Integer
' #End If
' Dim strDriver As String
' Dim strAttributes As String''

' strDriver = &quot;Microsoft Access Driver (*.mdb)&quot;
' 'Set the attributes delimited by null.
' 'See driver documentation for a complete
' 'list of supported attributes.
' 'strAttributes = &quot;SERVER=SomeServer&quot; & Chr$(0)
' strAttributes = strAttributes & &quot;DESCRIPTION=&quot; & gDSNname & Chr$(0)
' strAttributes = strAttributes & &quot;DSN=&quot; & gDSNname & Chr$(0)
' strAttributes = strAttributes & &quot;DATABASE=&quot; & gDSNname & Chr$(0)
' strAttributes = strAttributes & &quot;DBQ=c:\program files\...&quot; & gDSNname & Chr$(0)
' strAttributes = strAttributes & &quot;UID=ADMIN&quot; & Chr$(0)
' strAttributes = strAttributes & &quot;PWD=&quot; & Chr$(0)
' 'To show dialog, use Form1.Hwnd instead of vbAPINull.
' intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
' strDriver, strAttributes)
' If intRet Then
' MsgBox &quot;DSN Created&quot;
' Else
' MsgBox &quot;Create Failed&quot;
' End If
' 'retry to establish connection
' gConnect.Open (gDSNname)''''

Hope above code may be of use,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top