|
-
Oct 20th, 2003, 07:31 AM
#1
Thread Starter
Frenzied Member
database connection
is it possible to use one database connection throughout an application. The way I have it now I open a connection when I need it then close it.
It's tough being an unhandled exception...
___________
VB.NET 2008
VB.NET 2010
ORACLE 11g
CRYSTAL 11
-
Oct 20th, 2003, 09:08 AM
#2
Frenzied Member
you mean when the application is started the connection begins and remains connected until the application is closed???
You should be able to declare that in the app.config or web.config file, depending on which type of application you are creating.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Oct 20th, 2003, 09:11 AM
#3
Hyperactive Member
This is how I was taught to do it from the book "Visual Basic .Net For Access Databases"
Code:
' Dim and set connection string above control code
Dim cnn1 As System.Data.OleDb.OleDbConnection = connectToNorthwind()
Function connectToNorthwind() As System.Data.OleDb.OleDbConnection
Dim str1 As String = ("Provider=Microsoft.Jet.OLEDB.4.0;")
str1 += ("Data Source=C:\Visual Studio Projects\Access2k\Northwind.mdb")
Dim cnn1 As New System.Data.OleDb.OleDbConnection
cnn1.ConnectionString = str1
Return cnn1
End Function
Now you should be able to use it from any control. I think you could use a variation on that for any type database / situation.
-
Oct 20th, 2003, 09:18 AM
#4
Addicted Member
if you connect manualy the connection will stay open till you close it manualy ( like the exp above ), but if your using a dataadapter then the dataadapter will open and close the connection when needed
-
Oct 20th, 2003, 09:21 AM
#5
Frenzied Member
that's not completely true persianboy...with .NET's built in GC...any variables or references to variables that go out of scope with be collected by the GC and destroyed...so you can manually open the connection, but you don't have to manually close it, because one the connection loses it references, it is no longer in scope and the GC will come along and destroy it.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Oct 20th, 2003, 09:24 AM
#6
Addicted Member
but when the connection is active , there is no reason for the GC to collect it, so it will stay open while the program is running. plz tell me if i got anything wrong, thanks
-
Oct 20th, 2003, 10:35 AM
#7
Frenzied Member
you still have to take in to consideration the connection timeout when the connection is idle. If the connection hasn't been referenced (used) within a certain amount of time it will release the references and destroy the connection.
Why not just use connection pooling?
Last edited by Memnoch1207; Oct 20th, 2003 at 10:53 AM.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|