trouble with creating mulitple instances of a class

trouble with creating mulitple instances of a class

Post by Q2hyaX » Fri, 03 Dec 2004 06:25:09


I have a problem I can't get around. I am new to OOA/OOD/OOP.

I have created a class that will be an object for databases connections.
the class has a bunch of properties

sconnectstring = DFAppConnection.ConnectSQLServer(Me.txtdatabase.Text,
ConfigurationSettings.AppSettings.Item("CurrentDB"), Me.txtusername.Text,
Me.txtpassword.Text)
If sconnectstring <> "" Then
curdbconn = New DFAppConnection(True, sconnectstring,
Me.txtdatabase.Text, False, Me.txtusername.Text, Me.txtpassword.Text)
End If

sconnectstring =
DFAppConnection.ConnectSQLServer(Me.txtdatabase.Text,
ConfigurationSettings.AppSettings.Item("PreviousDB"), Me.txtusername.Text,
Me.txtpassword.Text)
If sconnectstring <> "" Then
prevdbconn = New DFAppConnection(True, sconnectstring,
Me.txtdatabase.Text, False, Me.txtusername.Text, Me.txtpassword.Text)
End If

I create 2 instances of this class in a row with different data
example: different connection string for each

I hope to use these 2 objects throughout my application for quick database
connections running sql code and what not.

Problem:
Keep getting the exact same properties values for each new class.
when I assign the new property it works great for the first new instance but
then
for the second one it becomes assigned the property value for the first one.

when i step through the code:

I can see inside the class the property is set for the class, but once I
skip out of the class and back into my form, any reference
to the property shows the same property for both classes. the database
connection string should be different in each but is'nt .

Please help if you have any ideas.

thank you

Chris
 
 
 

trouble with creating mulitple instances of a class

Post by Q2hyaX » Fri, 03 Dec 2004 07:01:14

Hi,

I figured it out,

I was sharing my class properties! apparently (again, I am new at this ) is
very bad in this particular situation