PC Review


Reply
Thread Tools Rate Thread

ADO error: "closed or invalid connection object"

 
 
Dave
Guest
Posts: n/a
 
      6th Jun 2004
Can anyone give me a clue as to why the following code is failing at the
"cmd.execute" line with a message "closed or invalid connection object:"


Dim objConn As ADODB.Connection
Dim cmd As New ADODB.Command

Dim sql As String

Set objConn = CurrentProject.Connection
sql = "SELECT * FROM test WHERE testid=1"

MsgBox (sql)

cmd.CommandText = sql
cmd.CommandType = adCmdText
cmd.Execute

Set cmd = Nothing
Set objConn = Nothing


 
Reply With Quote
 
 
 
 
Juan M Afán de Ribera
Guest
Posts: n/a
 
      6th Jun 2004
Hi,

you need to connect the command object to the data. So, you better do it
this other way

....

MsgBox (sql)

cmd.ActiveConnection = objConn
cmd.CommandText = sql
cmd.CommandType = adCmdText
cmd.Execute

....

HTH

--
Saludos :-)
Juan M Afan de Ribera [MVP Access]
http://www.mvp-access.com/juanmafan

"Dave" <(E-Mail Removed)> escribió en el mensaje
news:ubyyn9$(E-Mail Removed)...
> Can anyone give me a clue as to why the following code is failing at the
> "cmd.execute" line with a message "closed or invalid connection object:"
>
>
> Dim objConn As ADODB.Connection
> Dim cmd As New ADODB.Command
>
> Dim sql As String
>
> Set objConn = CurrentProject.Connection
> sql = "SELECT * FROM test WHERE testid=1"
>
> MsgBox (sql)
>
> cmd.CommandText = sql
> cmd.CommandType = adCmdText
> cmd.Execute
>
> Set cmd = Nothing
> Set objConn = Nothing
>
>



 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      6th Jun 2004
Ah, yes. Very good.

Thank you Juan.


"Juan M Afán de Ribera" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> you need to connect the command object to the data. So, you better do it
> this other way
>
> ...
>
> MsgBox (sql)
>
> cmd.ActiveConnection = objConn
> cmd.CommandText = sql
> cmd.CommandType = adCmdText
> cmd.Execute
>
> ...
>
> HTH
>
> --
> Saludos :-)
> Juan M Afan de Ribera [MVP Access]
> http://www.mvp-access.com/juanmafan
>
> "Dave" <(E-Mail Removed)> escribió en el mensaje
> news:ubyyn9$(E-Mail Removed)...
> > Can anyone give me a clue as to why the following code is failing at the
> > "cmd.execute" line with a message "closed or invalid connection object:"
> >
> >
> > Dim objConn As ADODB.Connection
> > Dim cmd As New ADODB.Command
> >
> > Dim sql As String
> >
> > Set objConn = CurrentProject.Connection
> > sql = "SELECT * FROM test WHERE testid=1"
> >
> > MsgBox (sql)
> >
> > cmd.CommandText = sql
> > cmd.CommandType = adCmdText
> > cmd.Execute
> >
> > Set cmd = Nothing
> > Set objConn = Nothing
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Webservice He!p - Response error: "An existing connection was forcibly closed by the remote host" even when no error in web method iKiLL Microsoft Dot NET Compact Framework 0 20th Dec 2006 04:14 PM
Webservice He!p - Response error: "An existing connection was forcibly closed by the remote host" even when no error in web method iKiLL Microsoft ASP .NET 0 20th Dec 2006 04:14 PM
"Expression you entered refer to an object that doesn't exist or is closed" error on subform silkworm Microsoft Access 3 18th Feb 2006 02:17 AM
"operation is not allowed when the object is closed" error when using VBA online help -- Resolution TC Microsoft Excel Programming 2 12th Jan 2005 09:05 AM
Access Problem: "Server error:..." OR "...Client closed connection" Jim Paullin Microsoft Frontpage 1 24th Jul 2003 04:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:28 AM.