Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Location
    Sweden
    Posts
    45

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

    Hi,
    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.

    Thanks,
    Robert

  2. #2
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    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

    DoEvents
    GblxDBPath = Space(200)
    vPath$ = App.Path & "\Application.ini"
    retc = GetPrivateProfileString("DATABASE", "DataBase", "?", GblxDBPath, 200, vPath$)
    DoEvents
    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
    MDIMain.Show
    frmStart.Show 1
    End Sub



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

    [DataBase]
    DATABASE=D:\CM\AssignmentsCM\R03.mdb

  3. #3
    Join Date
    Oct 2003
    Location
    Sweden
    Posts
    45
    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.

    Example:
    Code:
        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;"
            .Open
        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?

    EDIT!!
    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...
    /EDIT!!

    Happy weekend everybody!
    Robert
    Last edited by Rawbat; 10-24-03 at 09: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
  •