|
 |
access_asp thread: Object required: 'objConn' error
Message #1 by "Robert Harrigan" <rharrigan@f...> on Wed, 10 Jul 2002 15:12:43
|
|
I wrote a database and I can add and delete from the database. However,
when I try to modify something I get the following error:
Microsoft VBScript runtime error '800a01a8'
Object required: 'objConn'
/tradingpost_asp/Trade_Processor.asp, line 270
Here is the last chunk of my code:
'Close and dereference database objects
Set objCmd = Nothing
objConn.Close <----------------- Line 270
Set objConn = Nothing
%>
I copied the text straight from the book but it wont work. What am I
doing wrong?
Message #2 by "Larry Woods" <larry@l...> on Wed, 10 Jul 2002 15:58:47 -0700
|
|
Gotta' send more of the code.... Your three statements are fine.
Therefore you have problems elsewhere.
Larry Woods
> -----Original Message-----
> From: Robert Harrigan [mailto:rharrigan@f...]
> Sent: Wednesday, July 10, 2002 3:13 PM
> To: Access ASP
> Subject: [access_asp] Object required: 'objConn' error
>
>
> I wrote a database and I can add and delete from the
> database. However,
> when I try to modify something I get the following error:
>
> Microsoft VBScript runtime error '800a01a8'
> Object required: 'objConn'
> /tradingpost_asp/Trade_Processor.asp, line 270
>
> Here is the last chunk of my code:
>
> 'Close and dereference database objects
> Set objCmd = Nothing
> objConn.Close <----------------- Line 270
> Set objConn = Nothing
> %>
>
> I copied the text straight from the book but it wont
> work. What am I
> doing wrong?
>
Message #3 by "Ken Schaefer" <ken@a...> on Thu, 11 Jul 2002 11:20:15 +1000
|
|
Where is the code where you instantiate the ADO connection object?
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Robert Harrigan" <rharrigan@f...>
Subject: [access_asp] Object required: 'objConn' error
: I wrote a database and I can add and delete from the database. However,
: when I try to modify something I get the following error:
:
: Microsoft VBScript runtime error '800a01a8'
: Object required: 'objConn'
: /tradingpost_asp/Trade_Processor.asp, line 270
:
: Here is the last chunk of my code:
:
: 'Close and dereference database objects
: Set objCmd = Nothing
: objConn.Close <----------------- Line 270
: Set objConn = Nothing
: %>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Message #4 by "Robert Harrigan" <rharrigan@f...> on Thu, 11 Jul 2002 18:45:50
|
|
Here is the entire code:
<%
'Declare variables needed
Dim strInsert
Dim strValues
Dim strSQL
Dim adCmdText
Dim blnCriticalError
Dim blnFirstParameter
'Set required variables
adCmdText = 1
'***********************************************************
'* If an Add was requested, add the new club to the database
'***********************************************************
If Request.Form("Action") = "Add" Then
'Start building the SQL strings with the required fields
strInsert = "Insert into Items (FName,LName"
strValues = "Values('" & CStr(Request.Form("FName")) & _
"','" & CStr(Request.Form("LName")) & "'"
'Add account number if present
If Len(Request.Form("Acct")) > 0 Then
'Add the column name to the insert string
strInsert = strInsert & ",Acct"
'Add the value to the value string
strValues = strValues & ",'" & _
Cstr(Request.Form("Acct")) & "'"
End If
'Create and open the database object
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=Trade"
'Create the command object
Set objCmd = Server.CreateObject("ADODB.Command")
'Set the command object properties
Set objCmd.ActiveConnection = objConn
objCmd.CommandText = strInsert & ") " & strValues & ")"
objCmd.CommandType = adCmdText
'Execute the command
objCmd.Execute
'Display the insert string
Response.Write "The following insert string was executed and " & _
"the values inserted into the Clubs table.<P>"
Response.Write strInsert & ") " & strValues & ")"
'*************************************************************
'* If an Update was requested, update the club in the database
'*************************************************************
ElseIf Request.Form("Action") = "Update" Then
'Start building the SQL string
strSQL = "Update Items Set"
'Set the first parameter flag to true
blnFirstParameter = True
'Update First Name if present
If Len(Request.Form("FName")) > 0 Then
'Add the value to the SQL string
strSQL = strSQL & " FName = '" & _
Cstr(Request.Form("FName")) & "'"
'Set the first parameter flag to false
blnFirstParameter = False
End If
'Update Last Name if present
If Len(Request.Form("LName")) > 0 Then
'Add the value to the SQL string
If blnFirstParameter Then
strSQL = strSQL & " LName = '"
Else
strSQL = strSQL & ", LName = '"
End If
strSQL = strSQL & Cstr(Request.Form("LName")) & "'"
'Set the first parameter flag to false
blnFirstParameter = False
End If
'Update Account Number if present
If Len(Request.Form("Acct")) > 0 Then
'Add the value to the SQL string
If blnFirstParameter Then
strSQL = strSQL & " Acct = "
Else
strSQL = strSQL & ", Acct = "
End If
strSQL = strSQL & CLng(Request.Form("Acct"))
'Set the first parameter flag to false
blnFirstParameter = False
End If
'Set the Where clause
strSQL = strSQL & " Where Id = '" & _
Request.Form("Selection") & "'"
'Create and open the database object
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=Trade"
'Create the command object
Set objCmd = Server.CreateObject("ADODB.Command")
'Set the command object properties
Set objCmd.ActiveConnection = objConn
objCmd.CommandText = strSQL
objCmd.CommandType = adCmdText
'Execute the command
objCmd.Execute
'Display the update string
Response.Write "The following update string was executed and " & _
"the values updated in the Clubs table.<P>"
Response.Write strSQL
End If 'End If for step processing
'Close and dereference database objects
Set objCmd = Nothing
objConn.Close
Set objConn = Nothing
%>
Message #5 by "Larry Woods" <larry@l...> on Thu, 11 Jul 2002 13:16:45 -0700
|
|
Robert,
When I look at your code, I see that you are performing the
UPDATE based upon a field called "Id", which you define as STRING
('...') in your WHERE predicate. When I look at your ADD code, I
don't see that you are adding a field called "Id", therefore I
don't know how you can select on that field in your UPDATE.
Did I miss something?
Larry Woods
> -----Original Message-----
> From: Robert Harrigan [mailto:rharrigan@f...]
> Sent: Thursday, July 11, 2002 6:46 PM
> To: Access ASP
> Subject: [access_asp] Re: Object required: 'objConn' error
>
>
> Here is the entire code:
>
> <%
>
> 'Declare variables needed
> Dim strInsert
> Dim strValues
> Dim strSQL
> Dim adCmdText
> Dim blnCriticalError
> Dim blnFirstParameter
>
> 'Set required variables
> adCmdText = 1
>
> '***********************************************************
> '* If an Add was requested, add the new club to the database
> '***********************************************************
> If Request.Form("Action") = "Add" Then
>
> 'Start building the SQL strings with the required fields
> strInsert = "Insert into Items (FName,LName"
> strValues = "Values('" & CStr(Request.Form("FName")) & _
> "','" & CStr(Request.Form("LName")) & "'"
>
> 'Add account number if present
> If Len(Request.Form("Acct")) > 0 Then
> 'Add the column name to the insert string
> strInsert = strInsert & ",Acct"
> 'Add the value to the value string
> strValues = strValues & ",'" & _
> Cstr(Request.Form("Acct")) & "'"
> End If
>
> 'Create and open the database object
> Set objConn = Server.CreateObject("ADODB.Connection")
> objConn.Open "DSN=Trade"
>
> 'Create the command object
> Set objCmd = Server.CreateObject("ADODB.Command")
>
> 'Set the command object properties
> Set objCmd.ActiveConnection = objConn
> objCmd.CommandText = strInsert & ") " & strValues & ")"
> objCmd.CommandType = adCmdText
>
> 'Execute the command
> objCmd.Execute
>
> 'Display the insert string
> Response.Write "The following insert string was
> executed and " & _
> "the values inserted into the Clubs table.<P>"
> Response.Write strInsert & ") " & strValues & ")"
>
> '*************************************************************
> '* If an Update was requested, update the club in the database
> '*************************************************************
> ElseIf Request.Form("Action") = "Update" Then
>
> 'Start building the SQL string
> strSQL = "Update Items Set"
>
> 'Set the first parameter flag to true
> blnFirstParameter = True
>
> 'Update First Name if present
> If Len(Request.Form("FName")) > 0 Then
> 'Add the value to the SQL string
> strSQL = strSQL & " FName = '" & _
> Cstr(Request.Form("FName")) & "'"
> 'Set the first parameter flag to false
> blnFirstParameter = False
> End If
>
> 'Update Last Name if present
> If Len(Request.Form("LName")) > 0 Then
> 'Add the value to the SQL string
> If blnFirstParameter Then
> strSQL = strSQL & " LName = '"
> Else
> strSQL = strSQL & ", LName = '"
> End If
> strSQL = strSQL &
> Cstr(Request.Form("LName")) & "'"
> 'Set the first parameter flag to false
> blnFirstParameter = False
> End If
>
> 'Update Account Number if present
> If Len(Request.Form("Acct")) > 0 Then
> 'Add the value to the SQL string
> If blnFirstParameter Then
> strSQL = strSQL & " Acct = "
> Else
> strSQL = strSQL & ", Acct = "
> End If
> strSQL = strSQL &
> CLng(Request.Form("Acct"))
> 'Set the first parameter flag to false
> blnFirstParameter = False
> End If
>
> 'Set the Where clause
> strSQL = strSQL & " Where Id = '" & _
> Request.Form("Selection") & "'"
>
> 'Create and open the database object
> Set objConn = Server.CreateObject("ADODB.Connection")
> objConn.Open "DSN=Trade"
>
> 'Create the command object
> Set objCmd = Server.CreateObject("ADODB.Command")
>
> 'Set the command object properties
> Set objCmd.ActiveConnection = objConn
> objCmd.CommandText = strSQL
> objCmd.CommandType = adCmdText
>
> 'Execute the command
> objCmd.Execute
>
> 'Display the update string
> Response.Write "The following update string was
> executed and " & _
> "the values updated in the Clubs table.<P>"
> Response.Write strSQL
>
> End If 'End If for step processing
>
> 'Close and dereference database objects
> Set objCmd = Nothing
> objConn.Close
> Set objConn = Nothing
> %>
Message #6 by "Robert Harrigan" <rharrigan@f...> on Thu, 11 Jul 2002 21:27:04
|
|
Larry,
The ID field is automatically generated in Access. I chose to use this as
the identifier because it is unique for each field where a name can be
duplicated by the user.
Robert
Message #7 by "Larry Woods" <larry@l...> on Thu, 11 Jul 2002 14:20:31 -0700
|
|
That's what I thought! The Autonumber field is NOT a string! It
is a long. Therefore you DON'T want single-quotes around the
value.
Larry Woods
> -----Original Message-----
> From: Robert Harrigan [mailto:rharrigan@f...]
> Sent: Thursday, July 11, 2002 9:27 PM
> To: Access ASP
> Subject: [access_asp] Re: Object required: 'objConn' error
>
>
> Larry,
>
> The ID field is automatically generated in Access. I
> chose to use this as
> the identifier because it is unique for each field
> where a name can be
> duplicated by the user.
>
> Robert
>
Message #8 by "Ken Schaefer" <ken@a...> on Fri, 12 Jul 2002 12:23:09 +1000
|
|
Your logic looks like this:
<%
If Request.Form("action") = "Add" then
' Create Connection
' Open Connection
Elseif Request.Form("action") = "Update" then
' Create Connection
' Open Connection
End If
' Close Connection
' Dispose of Connection
%>
Can you see how it might be possible that you fall straight to the last
little bit of code, then you try to close a connection that does not exist?
(Hence the "object required" error message?)
I suggest you try the following at the top of your page:
<%
Response.Write(Request.Form("action"))
Response.End
%>
and see what Request.Form("action") is actually equal to.
Also, I suggest that in future you match up your logic better (eg if you
open a connection inside a conditional, then you dispose of it inside the
conditional, or do everything outside the conditional).
Also, I suggest that you include an Else clause after the ElseIf clauses to
catch all the circumstances where something doesn't work as you expect.
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Robert Harrigan" <rharrigan@f...>
To: "Access ASP" <access_asp@p...>
Sent: Thursday, July 11, 2002 6:45 PM
Subject: [access_asp] Re: Object required: 'objConn' error
: Here is the entire code:
:
: <%
:
: 'Declare variables needed
: Dim strInsert
: Dim strValues
: Dim strSQL
: Dim adCmdText
: Dim blnCriticalError
: Dim blnFirstParameter
:
: 'Set required variables
: adCmdText = 1
:
: '***********************************************************
: '* If an Add was requested, add the new club to the database
: '***********************************************************
: If Request.Form("Action") = "Add" Then
:
: 'Start building the SQL strings with the required fields
: strInsert = "Insert into Items (FName,LName"
: strValues = "Values('" & CStr(Request.Form("FName")) & _
: "','" & CStr(Request.Form("LName")) & "'"
:
: 'Add account number if present
: If Len(Request.Form("Acct")) > 0 Then
: 'Add the column name to the insert string
: strInsert = strInsert & ",Acct"
: 'Add the value to the value string
: strValues = strValues & ",'" & _
: Cstr(Request.Form("Acct")) & "'"
: End If
:
: 'Create and open the database object
: Set objConn = Server.CreateObject("ADODB.Connection")
: objConn.Open "DSN=Trade"
:
: 'Create the command object
: Set objCmd = Server.CreateObject("ADODB.Command")
:
: 'Set the command object properties
: Set objCmd.ActiveConnection = objConn
: objCmd.CommandText = strInsert & ") " & strValues & ")"
: objCmd.CommandType = adCmdText
:
: 'Execute the command
: objCmd.Execute
:
: 'Display the insert string
: Response.Write "The following insert string was executed and " & _
: "the values inserted into the Clubs table.<P>"
: Response.Write strInsert & ") " & strValues & ")"
:
: '*************************************************************
: '* If an Update was requested, update the club in the database
: '*************************************************************
: ElseIf Request.Form("Action") = "Update" Then
:
: 'Start building the SQL string
: strSQL = "Update Items Set"
:
: 'Set the first parameter flag to true
: blnFirstParameter = True
:
: 'Update First Name if present
: If Len(Request.Form("FName")) > 0 Then
: 'Add the value to the SQL string
: strSQL = strSQL & " FName = '" & _
: Cstr(Request.Form("FName")) & "'"
: 'Set the first parameter flag to false
: blnFirstParameter = False
: End If
:
: 'Update Last Name if present
: If Len(Request.Form("LName")) > 0 Then
: 'Add the value to the SQL string
: If blnFirstParameter Then
: strSQL = strSQL & " LName = '"
: Else
: strSQL = strSQL & ", LName = '"
: End If
: strSQL = strSQL & Cstr(Request.Form("LName")) & "'"
: 'Set the first parameter flag to false
: blnFirstParameter = False
: End If
:
: 'Update Account Number if present
: If Len(Request.Form("Acct")) > 0 Then
: 'Add the value to the SQL string
: If blnFirstParameter Then
: strSQL = strSQL & " Acct = "
: Else
: strSQL = strSQL & ", Acct = "
: End If
: strSQL = strSQL & CLng(Request.Form("Acct"))
: 'Set the first parameter flag to false
: blnFirstParameter = False
: End If
:
: 'Set the Where clause
: strSQL = strSQL & " Where Id = '" & _
: Request.Form("Selection") & "'"
:
: 'Create and open the database object
: Set objConn = Server.CreateObject("ADODB.Connection")
: objConn.Open "DSN=Trade"
:
: 'Create the command object
: Set objCmd = Server.CreateObject("ADODB.Command")
:
: 'Set the command object properties
: Set objCmd.ActiveConnection = objConn
: objCmd.CommandText = strSQL
: objCmd.CommandType = adCmdText
:
: 'Execute the command
: objCmd.Execute
:
: 'Display the update string
: Response.Write "The following update string was executed and " & _
: "the values updated in the Clubs table.<P>"
: Response.Write strSQL
:
: End If 'End If for step processing
:
: 'Close and dereference database objects
: Set objCmd = Nothing
: objConn.Close
: Set objConn = Nothing
: %>
|
|
 |