VB6 connection string changing

I'm opening a SQL Server 2008 database from VB6

Dim MyCon As ADODB.Connection
MyCon.Open "Provider=SQLOLEDB.1;Server=DEV-PC\SQLEXPRESS;Database=;Uid=USERNAME; Pwd=PASSWORD;", "USERNAME", "PASSWORD"

Open in new window



When I type the following in the immediate window
? MyCon

I get this
Provider=SQLOLEDB.1;User ID=USERNAME;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=DEV-PC;Use Encryption for Data=False;Tag with column collation when possible=False;


Why is it changing my connectionstring?
koossaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
the servername and db name are "moved" to other properties of the adodb.connectin object on opening.

and on opening, some properties fetched from the server are "added" to the connection string (for information)
0
HooKooDooKuCommented:
Keep in mind that when you set the connection string, you are not simply setting the value of a variable.  You are actually calling a Property Let function.  The programmer of that object can have more code behind a Property function than just simply setting a variable.  

Here is a contrived example of a VB Class source code:
Private m_Long As Boolean
Private m_StrValue As String
Public Property Let StrValue(Data As String)
    If Len(Data) > 10 Then
        m_Long = True
    Else
        m_Long = False
    End If
    m_StrValue = Left$(Data, 10)
End Property
Public Property Get StrValue() As String
    If m_Long Then
        StrValue = m_StrValue & "..."
    Else
        StrValue = m_StrValue
    End If
End Property

Open in new window


If the class is named Class1, then you could have some code like the following:
Dim C as new Class1
Dim Str1 as String
Dim Str2 as String
Str1 = "123456789012"
C.StrValue = Str1
Str2 = C.StrValue
If Str1 <> Str2 Then
   MsgBox "They Do Not Match"
End If

Open in new window

The line C.StrValue = Str1 would call Class1.Property Let StrValue.  That routine looks to see if the string is longer than 10 characters, and if so only stores the 1st 10 characters and sets a flag to indicate the string was too long.
The line Str2 = C.StrValue would call Class1.Property Get StrValue.  That routine returns the content of m_StrValue and appends "..." if the flag was set to indicate the original value given was too long.

So if you execute the above code, you will see the message "They Do Not Match" becase Str1 is "123456789012", while Str2 is "1234567890...".
0
koossaAuthor Commented:
In which properties is the server name and database name stored?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
if I remember correctly, it goes to the properties collection:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681519%28v=vs.85%29.aspx

the database actually selected will be the "Current Catalog" entry,
the server name goes to "Server Name" entry
all that was "removed" went to "Extended properties"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.