I'm hoping someone can tell me if this is the right or best way to do
this: (and do I want or need the Set cmd = Nothing, cnn.close, Set cnn
= Nothing???)
I'm setting cnn using the CurrentProject.Connection I don't see it
referenced to later...
I have dozens of functions cunstructed like this - are they all bogus?
Function myFunctionName()
On Err GoTo myErr
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim myLinkID as Long
myLink ID = someUniqueID
Set cnn = CurrentProject.Connection
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "mySPName"
cmd.CommandType = adCmdStoredProc
cmd.Execute , Parameters:=Array(myLinkID),
Options:=adExecuteNoRecords
myExit:
On Error Resume Next
Set cmd = Nothing
cnn.Close
Set cnn = Nothing
Exit Sub
myErr:
MsgBox Err.Number & " " & Err.Description
Resume myExit
End Sub 5 1234
"Lauren Quantrell" <la*************@hotmail.com> wrote in message
news:47**************************@posting.google.c om... I'm hoping someone can tell me if this is the right or best way to do this: (and do I want or need the Set cmd = Nothing, cnn.close, Set cnn = Nothing???) I'm setting cnn using the CurrentProject.Connection I don't see it referenced to later... I have dozens of functions cunstructed like this - are they all bogus?
Function myFunctionName() On Err GoTo myErr
Dim cnn As ADODB.Connection Dim cmd As ADODB.Command Dim myLinkID as Long myLink ID = someUniqueID Set cnn = CurrentProject.Connection Set cmd = New ADODB.Command Set cmd.ActiveConnection = CurrentProject.Connection cmd.CommandText = "mySPName" cmd.CommandType = adCmdStoredProc cmd.Execute , Parameters:=Array(myLinkID), Options:=adExecuteNoRecords
myExit: On Error Resume Next Set cmd = Nothing cnn.Close Set cnn = Nothing Exit Sub myErr: MsgBox Err.Number & " " & Err.Description Resume myExit End Sub
Unless you need some specific feature of the connection object you can just
create the command using CurrentProject.Connection. I like specify
parameters explicity - I think it is slightly faster since the code does not
need to query the server to determine data types, but we do this because it
helps when debugging to see what the data types are, and whether the params
are input or output. Also, i would qualify the procedure name, (usually this
means putting "dbo." in front). So i would do soemthing like this,
Sub mySubName()
On Err GoTo myErr
Dim cmd As ADODB.Command
Dim prm As ADODB.Parameter
Dim myLinkID as Long
myLink ID = someUniqueID
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "dbo.mySPName"
cmd.CommandType = adCmdStoredProc
Set prm = cmd.CreateParameter("@LinkID", adInteger, adParamInput, ,
myLinkID)
cmd.Parameters.Append prm
cmd.Execute ,, adExecuteNoRecords
myExit:
Set prm = Nothing
Set cmd = Nothing
Exit Sub
myErr:
MsgBox Err.Number & " " & Err.Description
Resume myExit
End Sub
John,
Thanks for your answer. I will change all my code.
But how do I write this for SPs with more than one param?
Set prm = cmd.CreateParameter("@LinkID", adInteger, adParamInput, , myLinkID)
cmd.Parameters.Append prm
"John Winterbottom" <as******@hotmail.com> wrote in message news:<c5*************@ID-185006.news.uni-berlin.de>... "Lauren Quantrell" <la*************@hotmail.com> wrote in message news:47**************************@posting.google.c om... I'm hoping someone can tell me if this is the right or best way to do this: (and do I want or need the Set cmd = Nothing, cnn.close, Set cnn = Nothing???) I'm setting cnn using the CurrentProject.Connection I don't see it referenced to later... I have dozens of functions cunstructed like this - are they all bogus?
Function myFunctionName() On Err GoTo myErr
Dim cnn As ADODB.Connection Dim cmd As ADODB.Command Dim myLinkID as Long myLink ID = someUniqueID Set cnn = CurrentProject.Connection Set cmd = New ADODB.Command Set cmd.ActiveConnection = CurrentProject.Connection cmd.CommandText = "mySPName" cmd.CommandType = adCmdStoredProc cmd.Execute , Parameters:=Array(myLinkID), Options:=adExecuteNoRecords
myExit: On Error Resume Next Set cmd = Nothing cnn.Close Set cnn = Nothing Exit Sub myErr: MsgBox Err.Number & " " & Err.Description Resume myExit End Sub
Unless you need some specific feature of the connection object you can just create the command using CurrentProject.Connection. I like specify parameters explicity - I think it is slightly faster since the code does not need to query the server to determine data types, but we do this because it helps when debugging to see what the data types are, and whether the params are input or output. Also, i would qualify the procedure name, (usually this means putting "dbo." in front). So i would do soemthing like this,
Sub mySubName() On Err GoTo myErr
Dim cmd As ADODB.Command Dim prm As ADODB.Parameter Dim myLinkID as Long myLink ID = someUniqueID Set cmd = New ADODB.Command Set cmd.ActiveConnection = CurrentProject.Connection cmd.CommandText = "dbo.mySPName" cmd.CommandType = adCmdStoredProc Set prm = cmd.CreateParameter("@LinkID", adInteger, adParamInput, , myLinkID) cmd.Parameters.Append prm cmd.Execute ,, adExecuteNoRecords
myExit: Set prm = Nothing Set cmd = Nothing Exit Sub
myErr: MsgBox Err.Number & " " & Err.Description Resume myExit End Sub
"Lauren Quantrell" <la*************@hotmail.com> wrote in message
news:47**************************@posting.google.c om... John, Thanks for your answer. I will change all my code. But how do I write this for SPs with more than one param?
Set prm = cmd.CreateParameter("@LinkID", adInteger, adParamInput, ,
myLinkID) cmd.Parameters.Append prm
add the additional parameters to the parameters collection in the same way:
Set prm = cmd.CreateParameter("@param1", adInteger, adParamInput, ,
param1Value)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("@param2", adVarchar, adParamInput, 50,
param2Value)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("@param3", adDouble, adParamInput, ,
param3Value)
cmd.Parameters.Append prm
That was a silly question I asked.
answer:
Set prm = cmd.CreateParameter("@LinkID", adInteger, adParamInput, , myLinkID)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("@LinkField", adInteger, adParamInput, , myLinkField)
cmd.Parameters.Append prm
etc...
lq la*************@hotmail.com (Lauren Quantrell) wrote in message news:<47**************************@posting.google. com>... John, Thanks for your answer. I will change all my code. But how do I write this for SPs with more than one param?
Set prm = cmd.CreateParameter("@LinkID", adInteger, adParamInput, , myLinkID) cmd.Parameters.Append prm
"John Winterbottom" <as******@hotmail.com> wrote in message news:<c5*************@ID-185006.news.uni-berlin.de>... "Lauren Quantrell" <la*************@hotmail.com> wrote in message news:47**************************@posting.google.c om... I'm hoping someone can tell me if this is the right or best way to do this: (and do I want or need the Set cmd = Nothing, cnn.close, Set cnn = Nothing???) I'm setting cnn using the CurrentProject.Connection I don't see it referenced to later... I have dozens of functions cunstructed like this - are they all bogus?
Function myFunctionName() On Err GoTo myErr
Dim cnn As ADODB.Connection Dim cmd As ADODB.Command Dim myLinkID as Long myLink ID = someUniqueID Set cnn = CurrentProject.Connection Set cmd = New ADODB.Command Set cmd.ActiveConnection = CurrentProject.Connection cmd.CommandText = "mySPName" cmd.CommandType = adCmdStoredProc cmd.Execute , Parameters:=Array(myLinkID), Options:=adExecuteNoRecords
myExit: On Error Resume Next Set cmd = Nothing cnn.Close Set cnn = Nothing Exit Sub myErr: MsgBox Err.Number & " " & Err.Description Resume myExit End Sub
Unless you need some specific feature of the connection object you can just create the command using CurrentProject.Connection. I like specify parameters explicity - I think it is slightly faster since the code does not need to query the server to determine data types, but we do this because it helps when debugging to see what the data types are, and whether the params are input or output. Also, i would qualify the procedure name, (usually this means putting "dbo." in front). So i would do soemthing like this,
Sub mySubName() On Err GoTo myErr
Dim cmd As ADODB.Command Dim prm As ADODB.Parameter Dim myLinkID as Long myLink ID = someUniqueID Set cmd = New ADODB.Command Set cmd.ActiveConnection = CurrentProject.Connection cmd.CommandText = "dbo.mySPName" cmd.CommandType = adCmdStoredProc Set prm = cmd.CreateParameter("@LinkID", adInteger, adParamInput, , myLinkID) cmd.Parameters.Append prm cmd.Execute ,, adExecuteNoRecords
myExit: Set prm = Nothing Set cmd = Nothing Exit Sub
myErr: MsgBox Err.Number & " " & Err.Description Resume myExit End Sub
That was a silly question I asked.
answer:
Set prm = cmd.CreateParameter("@LinkID", adInteger, adParamInput, , myLinkID)
cmd.Parameters.Append prm
Set prm = cmd.CreateParameter("@LinkField", adInteger, adParamInput, , myLinkField)
cmd.Parameters.Append prm
etc...
lq la*************@hotmail.com (Lauren Quantrell) wrote in message news:<47**************************@posting.google. com>... John, Thanks for your answer. I will change all my code. But how do I write this for SPs with more than one param?
Set prm = cmd.CreateParameter("@LinkID", adInteger, adParamInput, , myLinkID) cmd.Parameters.Append prm
"John Winterbottom" <as******@hotmail.com> wrote in message news:<c5*************@ID-185006.news.uni-berlin.de>... "Lauren Quantrell" <la*************@hotmail.com> wrote in message news:47**************************@posting.google.c om... I'm hoping someone can tell me if this is the right or best way to do this: (and do I want or need the Set cmd = Nothing, cnn.close, Set cnn = Nothing???) I'm setting cnn using the CurrentProject.Connection I don't see it referenced to later... I have dozens of functions cunstructed like this - are they all bogus?
Function myFunctionName() On Err GoTo myErr
Dim cnn As ADODB.Connection Dim cmd As ADODB.Command Dim myLinkID as Long myLink ID = someUniqueID Set cnn = CurrentProject.Connection Set cmd = New ADODB.Command Set cmd.ActiveConnection = CurrentProject.Connection cmd.CommandText = "mySPName" cmd.CommandType = adCmdStoredProc cmd.Execute , Parameters:=Array(myLinkID), Options:=adExecuteNoRecords
myExit: On Error Resume Next Set cmd = Nothing cnn.Close Set cnn = Nothing Exit Sub myErr: MsgBox Err.Number & " " & Err.Description Resume myExit End Sub
Unless you need some specific feature of the connection object you can just create the command using CurrentProject.Connection. I like specify parameters explicity - I think it is slightly faster since the code does not need to query the server to determine data types, but we do this because it helps when debugging to see what the data types are, and whether the params are input or output. Also, i would qualify the procedure name, (usually this means putting "dbo." in front). So i would do soemthing like this,
Sub mySubName() On Err GoTo myErr
Dim cmd As ADODB.Command Dim prm As ADODB.Parameter Dim myLinkID as Long myLink ID = someUniqueID Set cmd = New ADODB.Command Set cmd.ActiveConnection = CurrentProject.Connection cmd.CommandText = "dbo.mySPName" cmd.CommandType = adCmdStoredProc Set prm = cmd.CreateParameter("@LinkID", adInteger, adParamInput, , myLinkID) cmd.Parameters.Append prm cmd.Execute ,, adExecuteNoRecords
myExit: Set prm = Nothing Set cmd = Nothing Exit Sub
myErr: MsgBox Err.Number & " " & Err.Description Resume myExit End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Fortepianissimo |
last post by:
Here is the situation: I want my server started up upon connection.
When the first connection comes in, the server is not running. The
client realizes the fact, and then starts up the server and...
|
by: Paul Robinson |
last post by:
I am developing a website in ASP that connects to a Sybase database.
However, when I try to open a connection to the database the page will not
load. The script does not timeout, nor the...
|
by: Fred Zuckerman |
last post by:
Hello All,
After reading in this group about the preference for connecting to a SQL
Server using a connection string instead of a DSN file, I have done just
that.
BUT, I cannot update my data....
|
by: Sharon |
last post by:
Hi all.
I'm trying first time async socket connection.
In all the examples i've seen, the server connection is closed
when the message is complete.
Is it common to close the connection after...
|
by: Martin B |
last post by:
Hallo!
I'm working with C# .NET 2.0, implementing Client/Server Applications which
are connecting via Network to SQL-Server or Oracle Databases.
To stay independent from the underlaying Database...
|
by: Suresh |
last post by:
Hi Guys
I have Db2 server installed on remote server. i am connecting to that
remote server by using VPN.
I want to connect that remote DB2 server instance using my local
machine DB2...
|
by: crbd98 |
last post by:
Hello All,
Some time ago, I implemented a data access layer that included a simple
connectin pool. At the time, I did it all by myself: I created N
connections, each connection associated with...
|
by: Sankalp |
last post by:
Hi,
I am using VB 2005. My application has many data bound controls. The
connection is stored in the app.config file.
I want the application to start with a default connection string and
while...
|
by: fniles |
last post by:
I am using VS2003 and connecting to MS Access database.
When using a connection pooling (every time I open the OLEDBCONNECTION I use
the exact matching connection string),
1. how can I know how...
|
by: Johnson |
last post by:
I'm trying to fix a "sub optimal" situation with respect to connection
string management. Your thoughtful responses will be appreciated.
I just started with a new client who has a bunch of legacy...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |