For my application, should the data connection object be a global variable?
I'm creating a new class "XMLFile" in my application.
Should I pass it the ADO Connection object (byref) in the constructor function?
Or should I create a static class and create a global connection variable?
-> Here as an instance of the class is created, a connection object is passed to it, and the constructor sets the class-level connection variable (madoConn) with a reference to the connection object.
Public Class XMLFile
Public Sub New(ByRef ladoConn As SqlConnection)
madoConn = ladoConn
End Sub
End Class
Re: For my application, should the data connection object be a global variable?
ADO.NET is not ADO. They are two different things. ADO.NET has been designed specifically so that connections should be created and opened only when needed and closed and discarded immediately afterwards. Follow the CodeBank link in my signature and check out my thread on Retrieving & Saving Data for some examples of how to create and use database connection objects.