If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > How do I get Server from Connection after Prompt

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-23-03, 18:51
Rawbat Rawbat is offline
Registered User
 
Join Date: Oct 2003
Location: Sweden
Posts: 45
Question 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
Reply With Quote
  #2 (permalink)  
Old 10-24-03, 07:40
Marvels Marvels is offline
Registered User
 
Join Date: Jul 2003
Location: Amsterdam, Nederland
Posts: 449
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
Reply With Quote
  #3 (permalink)  
Old 10-24-03, 08:25
Rawbat Rawbat is offline
Registered User
 
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 08:34.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On