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.
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
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
If Len(GblxDBPath) = 0 Then Exit Sub
GblxDB = GblxDBPath
GblCheck = False
This is what the XXX.INI looks like, infact its an txt file saved as extention .INI
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
.Provider = "SQLOLEDB"
' Set to prompt if required.
.Properties("Prompt") = adPromptCompleteRequired
.ConnectionString = "DATA SOURCE=localhost;Integrated Security=SSPI;"
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.
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...