Solved

adPromptNever not working with DB2 Connection

Posted on 2008-10-28
1
336 Views
Last Modified: 2013-11-27
I'm trying to get the correct connection string down to connect to a DB2 table that is linked to a query. The connection string itself appears to be correct as it is not throwing any errors, however, I am still getting prompted for a username and password even though it is embedded in the connection string. I've tried this same method with Teradata tables and it works fine...  Any ideas?

Private Sub CalcKim_Click()
Dim cnUDB As ADODB.Connection
Set cnUDB = New ADODB.Connection
With cnUDB
.Provider = "IBMDADB2"
.ConnectionString = "Data Source=DB2PSN;UID=c1teh;PWD=test1"
.Properties("Prompt") = adPromptNever
.Open
End With


This works

as does this:

cnUDB.Open "Provider=IBMDADB2;Data Source=DB2PSN;UID=c1teh;PWD=test1"

no errors, yet still prompting for user and pass...
0
Comment
Question by:c9k9h
1 Comment
 
LVL 16

Accepted Solution

by:
Chuck Wood earned 500 total points
ID: 22825851
If you have IBM Client Access or IBM iSeries Access for Windows installed on your computer, you can use this code:
'===========================================================

'  requires:

'    reference to:

'       Microsoft ActiveX Data Objects 2.5 Library or later

'===========================================================

' set up global variables

Public strPassword As String

Public strUserName As String
 

' requires IBM Client Access or IBM iSeries Access for Windows be installed on the local computer

Public Function GetAS400Data(ByRef avarData() As Variant, ByVal strSQL As String, _

  ByVal strUserName As String, ByVal strPassword As String, ByVal strLibrary As String, _

  ByVal strSystem As String, Optional ByVal strRows As String = "") As Boolean

' set up error handling

On Error GoTo ErrorHandler

    Dim rst As New ADODB.Recordset, intI As Integer, strConnect As String

    ' set the initial state of the function

    GetAS400Data = False

    ' create the connect string

    strConnect = CreateConnectString(strUserName, strPassword, strLibrary, strSystem)

    With rst

        ' turn off error handling

        On Error Resume Next

        ' open the recordset

        .Open strSQL, strConnect

        ' if there was an error

        If err.Number <> 0 Then

            ' clear the error

            err.Clear

            ' turn error handling back on

            On Error GoTo ErrorHandler

            ' open the recordset

            .Open strSQL, strConnect

        End If

        ' turn error handling back on

        On Error GoTo ErrorHandler

        If Not .EOF Then

            ' if the rows string is blank,

            If strRows = "" Then

                ' load the data into the array

                avarData = .GetRows()

            Else

                ' load the number of rows into the array

                avarData = .GetRows(strRows)

            End If

            DoEvents

            ' set the function state to true

            GetAS400Data = True

        End If

        .Close

    End With

    Set rst = Nothing

ExitHere:

    Exit Function

ErrorHandler:

    MsgBox "Error:" & err.Number & vbCrLf & "Description:" & err.Description & vbCrLf & "From:" & _

        err.Source & vbCrLf & "In:basAS400Data_GetAS400Data", vbExclamation, "Program Error"

    Resume ExitHere

End Function
 

' Creates an AS/400 ADODB connection string using the Client Access ODBC driver

Public Function CreateConnectString(ByVal strUserName As String, ByVal strPassword As String, _

    ByVal strLibrary As String, ByVal strSystem As String) As String

' set up error handling

On Error GoTo ErrorHandler

    ' create the AS/400 connection string

    CreateConnectString = "Provider=MSDASQL.1;" & _

        "Driver=Client Access ODBC Driver (32-bit);" & _

        "Persist Security Info=True;" & _

        "User ID=" & strUserName & ";" & _

        "Password=" & strPassword & ";" & _

        "Connect Timeout=120;" & _

        "General Timeout=120;" & _

        "Extended Properties=" & _

        "SYSTEM=" & strSystem & ";" & _

        "DBQ=" & strLibrary & ";" & _

        "CMT=0;NAM=0;DFT=5;DSP=1;TFT=0;TSP=0;DEC=0;XDYNAMIC=1;" & _

        "RECBLOCK=2;BLOCKSIZE=512;SCROLLABLE=0;TRANSLATE=1;" & _

        "LAZYCLOSE=1;LIBVIEW=0;REMARKS=1;CONNTYPE=0;SORTTYPE=0;" & _

        "PREFETCH=0;DFTPKGLIB=QGPL;LANGUAGEID=ENU;SORTWEIGHT=0;" & _

        "SSL=2;MAXFIELDLEN=32;COMPRESSION=1;ALLOWUNSCHAR=0;"

ExitHere:

    Exit Function

ErrorHandler:

    MsgBox "Error:" & err.Number & vbCrLf & "Description:" & err.Description & vbCrLf & "From:" & _

        err.Source & vbCrLf & "In:basAS400Data_CreateConnectString", vbExclamation, "Program Error"

    CreateConnectString = ""

    Resume ExitHere

End Function

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

914 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

14 Experts available now in Live!

Get 1:1 Help Now