Passing values to New Class instance

  • Thread starter Thread starter NachoShaw
  • Start date Start date
N

NachoShaw

Guest
Hey

I have a simple class set up to make a string connection. I have added some properties to be populated when instantiated



Public Property DataSource As String = String.Empty
Public Property InitialCatalog As String = String.Empty
Public Property UserID As String = String.Empty
Public Property Password As String = String.Empty
Public Property MultipleActiveResultSets As Boolean = False

Public ConnString As String =
$"data source={DataSource};Initial Catalog={InitialCatalog};user ID={UserID};password={Password};MultipleActiveResultSets={MultipleActiveResultSets}"


Then i am trying to populate the Properties from the New Sub

Public Sub New(ByRef DatasourceOrigin As String)
Debug.Print("Inside New")
Select Case DatasourceOrigin
Case "local"
DataSource = "" 'ipAddress 1
UserID = "SomeUserName"
Password = "SomePassword"
InitialCatalog = "DatabaseName1"
Case "Remote"
DataSource = "" 'ipAddress 2
UserID = "SomeUserName"
Password = "SomePassword"
InitialCatalog = "DatabaseName2"
Case "server"
DataSource = "" 'ipAddress 3
UserID = "SomeUserName"
Password = "SomePassword"
InitialCatalog = "DatabaseName3"
End Select
End Sub

There are 3 options i am trying to pass. Local, Remote, Server. When i run it, nothing inside of the New sub is fired. When i step through, i step to New but then it moves straight to the next method without going through New sub itself.

My objective is use a single constructor method to create a connection string based on the type of datasource used in the New declaration which i am doing like this:

Dim ED_Conn As ClassConn = New ClassConn("local")
But none of my properties are getting populated.


What am i doing wrong?



Thanks



Im a self taught VB.Net guy who writes code for Autodesk Inventor. I may not know the terminology but i try so please be patient. Im not a kid so please dont treat me like one :)

Continue reading...
 
Back
Top