Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ERROR 424 Object Required

Status
Not open for further replies.

stemitch2000

Programmer
Nov 12, 2003
47
0
0
GB
Hello guys, this migrating to new server thing is really starting to annoy me!! OK, the situation. I have the following piece of code in a include file.

On Error Resume Next

function OpenDB
dim con
On Error Resume Next
err.clear
set con = session("con")
If Not (IsObject(con)) Then
response.write "opening new connection"
Set con = Server.CreateObject("ADODB.Connection")
set session("con") = con

if err.number <> 0 then
response.write err.number
response.write err.description
response.write &quot;before open con&quot;
end if

strDSN = Session(&quot;strDSN&quot;)
con.Open &quot;DSN=&quot; & strDSN
response.write &quot;opened new session successfully&quot;
Else
response.write &quot;did not open new session&quot;
'do nadda!
End If

If err.number <> 0 Then
err_count = 1
Response.write(&quot;Database Errors Occured&quot; & &quot;<P>&quot;)
Response.write(&quot;Error #&quot; & err.number & &quot;<P>&quot;)
Response.write(&quot;Error desc.&quot; & err.description & &quot;<P>&quot;)
End If

openDB = con
End function

I keep getting the following error (first time I run the code the second time it thinks there is a connection so pass through this function ok)

ERROR 424
OBJECT REQUIRED

Can anyone tell me where I am going wrong?
 
Does it tell you whic line is throwing the error?


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
It doesn't as such - but the first error checking bit does produce the error, so I think it is something to do with the

Set con = Server.CreateObject(&quot;ADODB.Connection&quot;)
set session(&quot;con&quot;) = con

since the last post I commented out the
set con = session(&quot;con&quot;)
and it went through the code alright, until i called openDB and I got the same error.
 
The error is because you are using SET word. Which in this case it expects to have an valid object on the right side but since the first time Session(&quot;con&quot;) is empty that is the error.

You could use something like this instead
If session(&quot;con&quot;)=&quot;&quot; Then
'open e new connection.
set session(&quot;con&quot;)= con
end if
'if it's alreadey opened then start using it
set con=session(&quot;con&quot;)


________
George, M
 
Could I put my code to set up the connection in the following place?


If session(&quot;con&quot;)=&quot;&quot; Then
'open e new connection.
<<code>>
set session(&quot;con&quot;)= con
end if
'if it's alreadey opened then start using it
set con=session(&quot;con&quot;)
 
another question, when I am making a call to the function above, do I call it like this?

set con = OpenDB()

or is this syntaxly incorrect?
 
Yes you place the code exactly there.

set con = OpenDB() will work if you will return an object

function OpenDB
set newConn=Server.CreateObject(&quot;ADODB.Connection&quot;)
'open your new connection
OpenDB=newConn
end function
...

If session(&quot;con&quot;)=&quot;&quot; Then
'open e new connection.
set session(&quot;con&quot;)= OpenDB
end if
'if it's alreadey opened then start using it
set con=session(&quot;con&quot;)


________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top