473,385 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

? about adp and connections

Using A2K and adp. Is it necessary to open a connection (to SQL
Server 2000) everytime you call a stored procedure or open a
recordset? Or will opening a connection one time do, like at
Form_Open?

I have a number of combo boxes that call the following public sub when
the NotInList event is fired:

Public Sub InsertItem(strCommandText As String, strParameterName As
String, _
adType As DataTypeEnum, lngSize As Long, strNewData As String)
On Error GoTo InsertItem_Error

Dim cmdInsert As ADODB.Command
Dim prm As Parameter
Const conQuote = """"

Set cnn = New ADODB.Connection
cnn.ConnectionString = GetConnectString
cnn.Open

Set cmdInsert = New ADODB.Command
With cmdInsert
Set .ActiveConnection = cnn
.CommandType = adCmdStoredProc
.CommandText = conQuote & strCommandText & conQuote
End With

Set prm = _
cmdInsert.CreateParameter(strParameterName, adType,
adParamInput, lngSize, strNewData)
cmdInsert.Parameters.Append prm

cmdInsert.Execute

Set cnn = Nothing

Exit Sub

....<error processing snipped>...
I set the connection, call the stored procedure, then close the
connection. I open recordsets in other parts of the form as
well...opening and closing the connection. Is it necessary to make
all these connections or can I just make one at Form_Open and close it
at Form_Close?
Nov 12 '05 #1
2 3538
ma**********@hotmail.com (Ellen Manning) wrote in
news:da*************************@posting.google.co m:
Using A2K and adp. Is it necessary to open a connection (to SQL
Server 2000) everytime you call a stored procedure or open a
recordset? Or will opening a connection one time do, like at
Form_Open?

I have a number of combo boxes that call the following public sub when
the NotInList event is fired:

Public Sub InsertItem(strCommandText As String, strParameterName As
String, _
adType As DataTypeEnum, lngSize As Long, strNewData As String)
On Error GoTo InsertItem_Error

Dim cmdInsert As ADODB.Command
Dim prm As Parameter
Const conQuote = """"

Set cnn = New ADODB.Connection
cnn.ConnectionString = GetConnectString
cnn.Open

Set cmdInsert = New ADODB.Command
With cmdInsert
Set .ActiveConnection = cnn
.CommandType = adCmdStoredProc
.CommandText = conQuote & strCommandText & conQuote
End With

Set prm = _
cmdInsert.CreateParameter(strParameterName, adType,
adParamInput, lngSize, strNewData)
cmdInsert.Parameters.Append prm

cmdInsert.Execute

Set cnn = Nothing

Exit Sub

...<error processing snipped>...
I set the connection, call the stored procedure, then close the
connection. I open recordsets in other parts of the form as
well...opening and closing the connection. Is it necessary to make
all these connections or can I just make one at Form_Open and close it
at Form_Close?


I tend to open a connection a new connection for all code interaction with
the db. Can you keep one open? Sure you can, and you can use it as long as
it's in scope. And of course you can use CurrentProject.Connection, but it is
painfully slow; I have found that opening a simple connection using the
BaseConnectionString is much faster. I'm assuming you are doing this using
your GetConnectString function.

I use a Public Function to give me a quickie connection:

Public Function MinimalADODBConnection(Optional ByVal CursorLocation As
ADODB.CursorLocationEnum = adUseServer) As ADODB.Connection
Set MinimalADODBConnection = New ADODB.Connection
With MinimalADODBConnection
.ConnectionString = CurrentProject.BaseConnectionString
.CursorLocation = CursorLocation
.Open
End With
End Function

and use it thus:

Set r = New ADODB.Recordset
With r
.ActiveConnection = MinimalADODBConnection()
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "Blah Blah"

I believe it is not necessary to release ADO object references and that in
this code there is no need or reason to set the connection to nothing
(there's no object variable to set to nothing anyway).

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #2
Lyle Fairfield <Mi************@Invalid.Com> wrote in message news:<Xn*******************@130.133.1.4>...
ma**********@hotmail.com (Ellen Manning) wrote in
news:da*************************@posting.google.co m:
Using A2K and adp. Is it necessary to open a connection (to SQL
Server 2000) everytime you call a stored procedure or open a
recordset? Or will opening a connection one time do, like at
Form_Open?

I have a number of combo boxes that call the following public sub when
the NotInList event is fired:

Public Sub InsertItem(strCommandText As String, strParameterName As
String, _
adType As DataTypeEnum, lngSize As Long, strNewData As String)
On Error GoTo InsertItem_Error

Dim cmdInsert As ADODB.Command
Dim prm As Parameter
Const conQuote = """"

Set cnn = New ADODB.Connection
cnn.ConnectionString = GetConnectString
cnn.Open

Set cmdInsert = New ADODB.Command
With cmdInsert
Set .ActiveConnection = cnn
.CommandType = adCmdStoredProc
.CommandText = conQuote & strCommandText & conQuote
End With

Set prm = _
cmdInsert.CreateParameter(strParameterName, adType,
adParamInput, lngSize, strNewData)
cmdInsert.Parameters.Append prm

cmdInsert.Execute

Set cnn = Nothing

Exit Sub

...<error processing snipped>...
I set the connection, call the stored procedure, then close the
connection. I open recordsets in other parts of the form as
well...opening and closing the connection. Is it necessary to make
all these connections or can I just make one at Form_Open and close it
at Form_Close?


I tend to open a connection a new connection for all code interaction with
the db. Can you keep one open? Sure you can, and you can use it as long as
it's in scope. And of course you can use CurrentProject.Connection, but it is
painfully slow; I have found that opening a simple connection using the
BaseConnectionString is much faster. I'm assuming you are doing this using
your GetConnectString function.

I use a Public Function to give me a quickie connection:

Public Function MinimalADODBConnection(Optional ByVal CursorLocation As
ADODB.CursorLocationEnum = adUseServer) As ADODB.Connection
Set MinimalADODBConnection = New ADODB.Connection
With MinimalADODBConnection
.ConnectionString = CurrentProject.BaseConnectionString
.CursorLocation = CursorLocation
.Open
End With
End Function

and use it thus:

Set r = New ADODB.Recordset
With r
.ActiveConnection = MinimalADODBConnection()
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "Blah Blah"

I believe it is not necessary to release ADO object references and that in
this code there is no need or reason to set the connection to nothing
(there's no object variable to set to nothing anyway).

Thanks for your reply. I have a situation where I sporadically get
"3709 - The connection cannot be used to perform this operation. It
is either closed or invalid in this context." Since I open and close
connections all over the place in my adp, I thought maybe I'd
forgotten to close a connection somewhere. Then I got to wondering
why I open and close so many times and maybe I could just get away
with one open and one close. Maybe my problem lies elsewhere. Will
do some more checking.
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Randell D. | last post by:
Folks, I currently connect to my db with PHP code that uses non-persistent connections. I've read that persistent connections can help performance since a connection to the db will use an...
3
by: Mudge | last post by:
Hi, My hosting provider only allows me to use 50 connections to my MySQL database that my Web site will use. I don't know what this 50 connections means exactly. Does this mean that only 50...
4
by: Angelos | last post by:
I get this error mysql_pconnect Too many connections ... every now and then. Does anyone knows where it comes from ? There are a lot of sites running on the server and all of them use the...
1
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and...
2
by: Bob | last post by:
We have a production web site that's data intensive (save user input to DB and query for displaying) with the ASP.NET app part on one W2K server and SQL 2000 DB on another W2K server. I have set...
17
by: Peter Proost | last post by:
Hi Group, I've got an interesting problem, I don't know if this is the right group but I think so because everything I've read about it so far says it's a .net problem. Here's the problem, we're...
4
by: elyob | last post by:
Not really tried going two ways at once, but I have an include_once connection to a mysql_database, now I need to retrieve info from a second mysql_database .. My mysql_connects are getting...
1
by: marcfischman | last post by:
Please help. I have a website running on a linux/apache/mysql/php server. I receive about 8,000-10,000 visitors a day with about 200,000 to 300,000 page views. The server is a RedHat Linux...
13
by: PRP | last post by:
Hi, Our DBA has complained about the large number of connections from the aspnet_wp process. We have multiple web applications deployed in different virtual directories. I read that the way...
5
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.