473,804 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

? 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(strC ommandText As String, strParameterNam e As
String, _
adType As DataTypeEnum, lngSize As Long, strNewData As String)
On Error GoTo InsertItem_Erro r

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

Set cnn = New ADODB.Connectio n
cnn.ConnectionS tring = GetConnectStrin g
cnn.Open

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

Set prm = _
cmdInsert.Creat eParameter(strP arameterName, adType,
adParamInput, lngSize, strNewData)
cmdInsert.Param eters.Append prm

cmdInsert.Execu te

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 3555
ma**********@ho tmail.com (Ellen Manning) wrote in
news:da******** *************** **@posting.goog le.com:
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(strC ommandText As String, strParameterNam e As
String, _
adType As DataTypeEnum, lngSize As Long, strNewData As String)
On Error GoTo InsertItem_Erro r

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

Set cnn = New ADODB.Connectio n
cnn.ConnectionS tring = GetConnectStrin g
cnn.Open

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

Set prm = _
cmdInsert.Creat eParameter(strP arameterName, adType,
adParamInput, lngSize, strNewData)
cmdInsert.Param eters.Append prm

cmdInsert.Execu te

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
BaseConnectionS tring is much faster. I'm assuming you are doing this using
your GetConnectStrin g function.

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

Public Function MinimalADODBCon nection(Optiona l ByVal CursorLocation As
ADODB.CursorLoc ationEnum = adUseServer) As ADODB.Connectio n
Set MinimalADODBCon nection = New ADODB.Connectio n
With MinimalADODBCon nection
.ConnectionStri ng = CurrentProject. BaseConnectionS tring
.CursorLocation = CursorLocation
.Open
End With
End Function

and use it thus:

Set r = New ADODB.Recordset
With r
.ActiveConnecti on = MinimalADODBCon nection()
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimisti c
.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******* ************@13 0.133.1.4>...
ma**********@ho tmail.com (Ellen Manning) wrote in
news:da******** *************** **@posting.goog le.com:
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(strC ommandText As String, strParameterNam e As
String, _
adType As DataTypeEnum, lngSize As Long, strNewData As String)
On Error GoTo InsertItem_Erro r

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

Set cnn = New ADODB.Connectio n
cnn.ConnectionS tring = GetConnectStrin g
cnn.Open

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

Set prm = _
cmdInsert.Creat eParameter(strP arameterName, adType,
adParamInput, lngSize, strNewData)
cmdInsert.Param eters.Append prm

cmdInsert.Execu te

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
BaseConnectionS tring is much faster. I'm assuming you are doing this using
your GetConnectStrin g function.

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

Public Function MinimalADODBCon nection(Optiona l ByVal CursorLocation As
ADODB.CursorLoc ationEnum = adUseServer) As ADODB.Connectio n
Set MinimalADODBCon nection = New ADODB.Connectio n
With MinimalADODBCon nection
.ConnectionStri ng = CurrentProject. BaseConnectionS tring
.CursorLocation = CursorLocation
.Open
End With
End Function

and use it thus:

Set r = New ADODB.Recordset
With r
.ActiveConnecti on = MinimalADODBCon nection()
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimisti c
.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
2788
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 existing unused connection. If my system was to go through a busy period whereby I seen an extra 50% or more activity for ten minutes or so, would the extra connections stay alive for ever or is there a time limit of inactivity? Would the unused...
3
2414
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 visitors to my Web site can access my database through my Web site at one time? Or does this mean that in my code I can only use 50 connections? and like
4
4179
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 Database frequently. Is there any configuration that I will have to do to my server in order to handle the load ? Thank you... I would appreciate answers from someone that already experienced that
1
2568
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 close them as early as possible. My requirement is as follows: I'm developing a class library that will be instantiated by a COM component. My class library contains functions that perform lot of mathematical calculations and read a lot of data...
2
2127
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 up performance logs to log # of pooled database connections on the web server every 60 seconds (.NET CLR Data(_global_)\SqlClient: Current # pooled connections). The # of connections is constantly higher than the # of active ASP.NET sessions....
17
8455
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 using crystal reports 9 and vb.net and we're using the crystalrepotViewer to show our reports. But every time we open a report the connection to or sql server remains, so if I open 5 forms with the report viewer I've got 5 sleeping connections in...
4
6066
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 confused. So, (I've had a couple of beers), am I opening up too many at once? I'll look again in the morning, but am thinking that it is a bad idea to leave two connections open all the time ...
1
13687
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 server running PHP 5.x, MySQL 5.x, Apache 2.x We have been suffering from a number of performance issues. Our hosting company has set our max connections to 100, and we are using persistent connections in PHP. At times the mysqld process takes 100%...
13
1775
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 ADO.NET in-built connection pool works is per app domain. So in a scenario where I am using single connection string (from web.config) and I am closing all connections as recommended, is it correct to assume that ideal number of connections
5
3401
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 left, I always see that there are 2 connections open and in "ESTABLISHED" state. Here is the piece of code that I'm using, please tell where I'm doing it wrong. Since this class is being used at many placed in my actual web based application that...
0
9587
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.