ODBC API Creating DSN - Everyting Works except for Database 
Author Message
 ODBC API Creating DSN - Everyting Works except for Database

I am able to create a DSN with this code, but when I go to the second tab of
the ODBC adminstrator, I do not see the connection to the actual database.
It should say c:\oledbsdk\bin\nwind.mdb as my database, but it does not.
What am I doing wrong?  I know there are other methods of doing this, but I
want to learn how to do it with an API.  Thanks in advance.

Ken

'In general declarations
'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

'When I load the main form I do this
Sub RegisterDatabaseX()

#If Win32 Then
    Dim intRet As Long
#Else
    Dim intRet As Integer
#End If

Dim strDriver As String
Dim strAttributes As String

'Set the driver to SQL Server because it is most common.
strDriver = "Microsoft Access Driver (*.mdb)"      'Set the attributes
delimited by null.

'See driver documentation for a complete
'list of supported attributes.
strAttributes = "SERVER=SomeServer" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=Database Connection for
EZBusiness" & Chr$(0)
strAttributes = strAttributes & "DSN=EZBusiness" & Chr$(0)
strAttributes = strAttributes & "DATABASE=c:\oledbsdk\bin\nwind.mdb" &
Chr$(0)
strAttributes = strAttributes & "UID=" & Chr$(0)
strAttributes = strAttributes & "PWD=password" & Chr$(0)

'To show dialog, use Form1.Hwnd instead of vbAPINull.
intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
    strDriver, strAttributes)

If intRet Then
    MsgBox "DSN Created"
Else
    MsgBox "Create Failed"
End If

End Sub



Mon, 13 Nov 2000 03:00:00 GMT  
 ODBC API Creating DSN - Everyting Works except for Database

You'd get faster and better help from the microsoft.public.vb.database
and it's sub newsgroups.

Regards,

Elvio Serrao


Quote:
> I am able to create a DSN with this code, but when I go to the second
> tab of
> the ODBC adminstrator, I do not see the connection to the actual
> database.
> It should say c:\oledbsdk\bin\nwind.mdb as my database, but it does
> not.
> What am I doing wrong?  I know there are other methods of doing this,
> but I
> want to learn how to do it with an API.  Thanks in advance.

> Ken

> 'In general declarations
> '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

> 'When I load the main form I do this
> Sub RegisterDatabaseX()

> #If Win32 Then
>     Dim intRet As Long
> #Else
>     Dim intRet As Integer
> #End If

> Dim strDriver As String
> Dim strAttributes As String

> 'Set the driver to SQL Server because it is most common.
> strDriver = "Microsoft Access Driver (*.mdb)"      'Set the attributes

> delimited by null.

> 'See driver documentation for a complete
> 'list of supported attributes.
> strAttributes = "SERVER=SomeServer" & Chr$(0)
> strAttributes = strAttributes & "DESCRIPTION=Database Connection for
> EZBusiness" & Chr$(0)
> strAttributes = strAttributes & "DSN=EZBusiness" & Chr$(0)
> strAttributes = strAttributes & "DATABASE=c:\oledbsdk\bin\nwind.mdb" &

> Chr$(0)
> strAttributes = strAttributes & "UID=" & Chr$(0)
> strAttributes = strAttributes & "PWD=password" & Chr$(0)

> 'To show dialog, use Form1.Hwnd instead of vbAPINull.
> intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
>     strDriver, strAttributes)

> If intRet Then
>     MsgBox "DSN Created"
> Else
>     MsgBox "Create Failed"
> End If

> End Sub



Tue, 14 Nov 2000 03:00:00 GMT  
 ODBC API Creating DSN - Everyting Works except for Database

Change "DATABASE=" to "DBQ="



Quote:
> I am able to create a DSN with this code, but when I go to the second tab
of
> the ODBC adminstrator, I do not see the connection to the actual
database.
> It should say c:\oledbsdk\bin\nwind.mdb as my database, but it does not.
> What am I doing wrong?  I know there are other methods of doing this, but
I
> want to learn how to do it with an API.  Thanks in advance.

> Ken

> 'In general declarations
> '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

> 'When I load the main form I do this
> Sub RegisterDatabaseX()

> #If Win32 Then
>     Dim intRet As Long
> #Else
>     Dim intRet As Integer
> #End If

> Dim strDriver As String
> Dim strAttributes As String

> 'Set the driver to SQL Server because it is most common.
> strDriver = "Microsoft Access Driver (*.mdb)"      'Set the attributes
> delimited by null.

> 'See driver documentation for a complete
> 'list of supported attributes.
> strAttributes = "SERVER=SomeServer" & Chr$(0)
> strAttributes = strAttributes & "DESCRIPTION=Database Connection for
> EZBusiness" & Chr$(0)
> strAttributes = strAttributes & "DSN=EZBusiness" & Chr$(0)
> strAttributes = strAttributes & "DATABASE=c:\oledbsdk\bin\nwind.mdb" &
> Chr$(0)
> strAttributes = strAttributes & "UID=" & Chr$(0)
> strAttributes = strAttributes & "PWD=password" & Chr$(0)

> 'To show dialog, use Form1.Hwnd instead of vbAPINull.
> intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
>     strDriver, strAttributes)

> If intRet Then
>     MsgBox "DSN Created"
> Else
>     MsgBox "Create Failed"
> End If

> End Sub



Fri, 17 Nov 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Creating ODBC System DSN by using ODBC API ?

2. Create ODBC DSN for SQL Server using VB and API

3. Crystal and ODBC DSN/DSN-less connections - do I need USER DSN or SYSTEM DSN

4. odbc fil dsn oracle 8i connection won't work

5. Create ODBC connection without DSN

6. How to create ODBC DSN from Access 97

7. Trying to create a DSN on the fly for Oracle ODBC

8. how to create odbc dsn for SQL Server7

9. Creating ODBC DSN programmatically

10. Creating DSN with text odbc driver

11. Creating ODBC DSN programaticall..How?

12. VB3 - ODBC API - DSN ?

 

 
Powered by phpBB® Forum Software