Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003

    Question Unanswered: How do I get Server from Connection after Prompt

    I'm using a default connection string that should work for most installations, but the server may have a different name (or change) so I use the adPromptCompleteRequired setting.
    Now, this works excellent of course, but I would like to store the servername or the complete connectionstring for the next time.

    I took for granted the connection string or the connection properties would have been updated to reflect the user input from the prompt, but apparently not.

    Does anyone know how I get a hold of the selected server in a prompt. That is the actual running connection string.

    I use the SQLOLEDB.1 provider if that affects things.


  2. #2
    Join Date
    Jul 2003
    Amsterdam, Nederland

    Question WriteProfileString AND GetProfileString

    Hi there

    Here an example of en GetProfileString
    See your help file for a WriteProfileString
    infact the WriteProfileString writes a line where your current db is stored
    and the GetProfile string will read it the next time you log in

    Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

    Sub Main()
    Dim retc As Long 'Number
    Dim vPath$ 'String with path
    Dim x As Variant 'Variable
    On Error Resume Next

    GblxDBPath = Space(200)
    vPath$ = App.Path & "\Application.ini"
    retc = GetPrivateProfileString("DATABASE", "DataBase", "?", GblxDBPath, 200, vPath$)
    GblxDBPath = Mid(GblxDBPath, 1, retc)
    If GblxDBPath = "?" Then
    MsgBox "Coud not find DataBase in Application.ini !", vbCritical
    Exit Sub
    End If
    If Len(GblxDBPath) = 0 Then Exit Sub
    GblxDB = GblxDBPath

    GblCheck = False
    frmStart.Show 1
    End Sub

    This is what the XXX.INI looks like, infact its an txt file saved as extention .INI


  3. #3
    Join Date
    Oct 2003
    Hi Marvels,
    I think you misunderstood my question.
    I know how to persist settings, but I don't know how I can retrieve the servername from the ado connection after a user has chosen a server manually after being prompted to do so.

        Dim cn As ADODB.Connection
        Set cn = New ADODB.Connection
        With cn
            .Provider = "SQLOLEDB"
            ' Set to prompt if required.
            .Properties("Prompt") = adPromptCompleteRequired
            .ConnectionString = "DATA SOURCE=localhost;Integrated Security=SSPI;"
        End With
    Now, if the server (localhost) is incorrect the user will be prompted. After the user has chosen a server and the connection is established HOW do I get the server that the connection is established to?

    I would have thought the connection string would correlate to the actual connection.

    Any ideas?

    I now noted that with the code I posted I actually can read the updated Data Source, but with a DataEnvironment using MSDataShape I cannot...

    Happy weekend everybody!
    Last edited by Rawbat; 10-24-03 at 08:34.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts