Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

share ado.net connection

Status
Not open for further replies.

purplehaze1

Programmer
Jul 23, 2003
86
US
How can I share ado.net connection across multiple processes?
eg. I have two classes, clsimport and clsexport. I want to open a connection and execute processes in both classes using the same open connection object. Following is my procedure to open connection from yet another class module clsLogin.

Similarly, I want to share ConnectionString across all class modules.
How to do it? Any technical example will be very helpful. Thanks.



Function Connect() As Boolean
Try
ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info = False;" & _
"Initial Catalog = " & database & ";Data Source = " & Server & ";User ID =" & userName & ";Password =" & password & ";"
myConnection = New OleDbConnection(ConnectionString)
myConnection.Open()
myConnectFlag = True
Return True
Catch e As Exception
Console.WriteLine(e.ToString())
End Try

End Function
 
Y
ou can declare connection string and connection object in a module, which will enable you to use them in anywhere in your app. Although it is not advisable to leave the connection open through out the life of your application. It is always efficient to open the connection as and when required and close it as soon as task is accomplished.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top