Microsoft Visual Basic Design Patterns by William Stamatakis (VB6)

I believe the book above (published many years ago) utilizes Factory and Singelton design patterns to create database connections. Anyone has the code that was on CD? Or similar code for creating database Connection objects in .NET?
quasar_eeAsked:
Who is Participating?
 
Wayne Taylor (webtubbs)Commented:
Database connections in .Net are now done with ADO.Net. See here for an overview -> http://msdn.microsoft.com/en-us/library/h43ks021.aspx

Wayne
0
 
JackOfPHCommented:
I do not have the code for that book, but this sample will give you an idea...
Public Class DatabaseConnection

Private Shared _DatabaseConnection as SQLConnection

Private Sub New()

End Sub 

Public Function Initialized() as SQLConnection

If _DatabaseConnection is nothing then

_DatabaseConnection = new SQLConnection("YourConnectionStringHere")

End If

Return _DatabaseConnection
End Sub 

End Class

Open in new window

0
 
JackOfPHCommented:
tipo...

Code at the line 18 should be End Function

:)
0
 
JackOfPHCommented:
Here is the code without any error,

I also replace the line
Public Function Initialized() as SQLConnection

to

Public Shared Function Initialized() as SQLConnection

Try it...

Public Class DatabaseConnection

Private Shared _DatabaseConnection as SQLConnection

Private Sub New()

End Sub 

Public Shared Function Initialized() as SQLConnection

If _DatabaseConnection is nothing then

_DatabaseConnection = new SQLConnection("YourConnectionStringHere")

End If

Return _DatabaseConnection
End Function 

End Class

Open in new window

0
 
quasar_eeAuthor Commented:
all right
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.