Object required: 'objconn' (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


mar0364 -> Object required: 'objconn' (3/19/2005 17:36:44)

I have a form that submits to a table. This works great using a dsn to connect to the db. When I switch to using an include file dsnless and placing the connection in a variable name strconnect. I get the following error:
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'objconn'
/checkbox/add_action.asp, line 69


The only diffrence between the dsn and dsnless version are
top of dsnless page
'option explicit
 Dim strconnect
 Dim orsco
%>
<!--METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<!--#include file="connection.asp"-->

where the objconn is made on the dsnless
'Create and open the database object
	Set objconn = server.createobject("ADODB.Connection")
	objConn.Open, strconnect


The same bit of code on the one that uses a dsn
'Create and open the database object
	Set objconn = server.createobject("ADODB.Connection")
	objConn.Open, "dsn=onsite"


All the dsnless code
<%
 'option explicit
 Dim strconnect
 Dim orsco
%>
<!--METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<!--#include file="connection.asp"-->

<html>

Process the article
<%
	'Declare variable needed
	Dim strInsert
	Dim	strValue
	Dim AdCmdText
	Dim blnCrticalError

	'Set required variables
	adCmdText = 1
	
	'if an add was requested add a new article to the table.
	
	If Request.Form ("") = "Add" Then
	'start building the SQL string with the required fields
	strInsert = "Insert into tblonsite (article_date,article_text"
	strValues = "Values('" &CStr &(Request.Form("txtArticle_date")) &_
				"','" & CStr(Request.Form("txtArticle_text")) & "'"
				
				
	'Add acive if checked
	If Request.Form("") = 1 Then
	'Add the column name to the insert string
	strInsert = strInsert &",article_status"
	'Add true to the value string
	strValue = strValue & ",True"
	End If
	
	'Create and open the database object
	Set objconn = server.createobject("ADODB.Connection")
	objConn.Open, strconnect
	
	'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 value inserted into the article table.</p>"
	Response.Write strInsert & ") " & strValue & ")"
	
	End If
	
	'Close and clean
	set objcmd = nothing
69	objconn.close
	set objconn = nothing			    	
%>	



The form is submitting all the info. I've response.write that. How can I fix this?




BeTheBall -> RE: Object required: 'objconn' (3/19/2005 19:43:05)

What's the code for connection.asp?




mar0364 -> RE: Object required: 'objconn' (3/19/2005 20:03:30)


quote:

ORIGINAL: BeTheBall

What's the code for connection.asp?

strconnect	=	"provider=microsoft.jet.oledb.4.0; " &_
					"data source=C:\Inetpub\wwwroot\checkbox\data\rl_company.mdb;" &_
					"persist security info=false"





BeTheBall -> RE: Object required: 'objconn' (3/19/2005 20:16:20)

Rich, I haven't diversified much with connections. I have one that works and use it every time. However, in the examples I have seen, there is no comma between:

objConn.Open, strconnect

Does it help if you use just:

objConn.Open strconnect




Giomanach -> RE: Object required: 'objconn' (3/19/2005 20:20:51)

Hi Rich

Duane is right in the comma causing the error, I think.

You only need the comma when you are using the createobject etc to run an SQL string:

objConn.Open strSQL, strconnect

Otherwise, it's just:

objConn.Open strconnect

Just backing up Duanes point[8|]




mar0364 -> RE: Object required: 'objconn' (3/19/2005 20:24:43)

Thanksbut. No same error.
quote:

ORIGINAL: BeTheBall

Rich, I haven't diversified much with connections. I have one that works and use it every time. However, in the examples I have seen, there is no comma between:

objConn.Open, strconnect

Does it help if you use just:

objConn.Open strconnect





Spooky -> RE: Object required: 'objconn' (3/19/2005 20:53:52)

If you use this code?

'Create and open the database object
	Set objConn = server.createobject("ADODB.Connection")
	objConn.Open strconnect
	objConn.execute (strInsert & ") " & strValue & ")"),,129

	'display the insert string
	Response.Write "the following insert string was executed " &_
				   "and the value inserted into the article table.</p>"
	Response.Write strInsert & ") " & strValue & ")"
	
	End If
	
	'Close and clean
	objConn.close
	set objConn = nothing			    	
%>




mar0364 -> RE: Object required: 'objconn' (3/19/2005 21:15:22)


Same problem. Spooky can't solve on the first try. I may be in over my head.
quote:

'Create and open the database object
Set objConn = server.createobject("ADODB.Connection")
objConn.Open strconnect
objConn.execute (strInsert & ") " & strValue & ")"),,129

'display the insert string
Response.Write "the following insert string was executed " &_
"and the value inserted into the article table.</p>"
Response.Write strInsert & ") " & strValue & ")"

End If

'Close and clean
objConn.close
set objConn = nothing




Spooky -> RE: Object required: 'objconn' (3/19/2005 23:39:12)

Using that code - it errors on which line?
(Also - post the complete page current code)




mar0364 -> RE: Object required: 'objconn' (3/20/2005 7:16:38)

First thanks for helping.

Original code error on line 70
<%
 'option explicit
 Dim strconnect
 Dim orsco
%>
<!--METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<!--#include file="connection.asp"-->

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Confirmation of adding article to Intranet</title>
</head>

<body>
Process the article
<%
	'Declare variable needed
	Dim strInsert
	Dim	strValue
	Dim AdCmdText
	Dim blnCrticalError

	'Set required variables
	adCmdText = 1
	
	'if an add was requested add a new article to the table.
	
	If Request.Form ("") = "Add" Then
	'start building the SQL string with the required fields
	strInsert = "Insert into tblonsite (article_date,article_text"
	strValues = "Values('" &CStr &(Request.Form("txtArticle_date")) &_
				"','" & CStr(Request.Form("txtArticle_text")) & "'"
				
				
	'Add active if checked
	If Request.Form("") = 1 Then
	'Add the column name to the insert string
	strInsert = strInsert &",article_status"
	'Add true to the value string
	strValue = strValue & ",True"
	End If
	
	'Create and open the database object
	Set objconn = server.createobject("ADODB.Connection")
	objConn.Open, strconnect
	
	 
    '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 value inserted into the article table.</p>"
	Response.Write strInsert & ") " & strValue & ")"
	
	End If
	
	'Close and clean
	set objcmd = nothing	
70		objconn.close
	set objconn = nothing
			    	
%>	
</body>

</html>



Code with changes error line 58

<%
 'option explicit
 Dim strconnect
 Dim orsco
%>
<!--METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<!--#include file="connection.asp"-->

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Confirmation of adding article to Intranet</title>
</head>

<body>
Process the article
<%
	'Declare variable needed
	Dim strInsert
	Dim	strValue
	Dim AdCmdText
	Dim blnCrticalError

	'Set required variables
	adCmdText = 1
	
	'if an add was requested add a new article to the table.
	
	If Request.Form ("") = "Add" Then
	'start building the SQL string with the required fields
	strInsert = "Insert into tblonsite (article_date,article_text"
	strValues = "Values('" &CStr &(Request.Form("txtArticle_date")) &_
				"','" & CStr(Request.Form("txtArticle_text")) & "'"
				
				
	'Add active if checked
	If Request.Form("") = 1 Then
	'Add the column name to the insert string
	strInsert = strInsert &",article_status"
	'Add true to the value string
	strValue = strValue & ",True"
	End If
	
	'Create and open the database object
	Set objConn = server.createobject("ADODB.Connection")
	objConn.Open strconnect
	objConn.execute (strInsert & ") " & strValue & ")"),,129

	'display the insert string
	Response.Write "the following insert string was executed " &_
				   "and the value inserted into the article table.</p>"
	Response.Write strInsert & ") " & strValue & ")"
	
	End If
	
	'Close and clean
58	objConn.close
	set objConn = nothing			    	
%>
</body>

</html>


Looks like they both error in the same place.




Spooky -> RE: Object required: 'objconn' (3/20/2005 14:10:49)

Hmmmm....

<%
strconnect="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\checkbox\data\rl_company.mdb"
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Confirmation of adding article to Intranet</title>
</head>
<body>
Process the article
<%
	'Declare variable needed
	Dim strInsert
	Dim	strValue
	Dim blnCrticalError
	
	'if an add was requested add a new article to the table.
	
	If Request.Form ("") = "Add" Then
	'start building the SQL string with the required fields
	strInsert = "Insert into tblonsite (article_date,article_text"
	strValues = "Values('"&CStr(Request.Form("txtArticle_date")) &_
				"','" & CStr(Request.Form("txtArticle_text")) & "'"
				
	'Add active if checked
	If Request.Form("") = 1 Then
	'Add the column name to the insert string
	strInsert = strInsert &",article_status"
	'Add true to the value string
	strValue = strValue & ",True"
	End If
	
	'Create and open the database object
	Set objConn = server.createobject("ADODB.Connection")
	objConn.Open strconnect
	objConn.execute(strInsert & ") " & strValue & ")"),,129

	'display the insert string
	Response.Write "the following insert string was executed " &_
				   "and the value inserted into the article table.</p>"
	Response.Write strInsert & ") " & strValue & ")"
	
	End If
	
	'Close and clean
	objConn.close
	set objConn = nothing			    	
%>
</body>

</html>




mar0364 -> RE: Object required: 'objconn' (3/20/2005 16:50:31)

Errors in the same darn place. I'm begining to think I should skin this cat another way. Suggestions anyone? It bugs me because this should work. I just don't get it.

Thanks
Rich




Spooky -> RE: Object required: 'objconn' (3/20/2005 16:55:20)

objConn.Open strconnect
response.write strInsert & ") " & strValue & ")"
response.end

objConn.execute(strInsert & ") " & strValue & ")"),,129


What does that give you?




mar0364 -> RE: Object required: 'objconn' (3/20/2005 18:14:06)

Samething brother.




Spooky -> RE: Object required: 'objconn' (3/20/2005 18:30:05)

and if you do this?

response.write strInsert & ") " & strValue & ")"
response.end

'Create and open the database object
Set objConn = server.createobject("ADODB.Connection")
objConn.Open strconnect
objConn.execute(strInsert & ") " & strValue & ")"),,129




mar0364 -> RE: Object required: 'objconn' (3/21/2005 9:20:28)

Same darn thing.

Thanks!
Rich




Spooky -> RE: Object required: 'objconn' (3/21/2005 13:45:48)

Are you sure you are modifying the right code then?
That should be ending the code before you even get to opening the objconn

The response end would have stopped the code in its tracks - you shouldnt have the same error.
Check exactly what file you are modifying and that you are testing the same/ right file.




mar0364 -> RE: Object required: 'objconn' (3/22/2005 15:06:12)

I'll try it again when I get home tonight. I'm sure your be able to check up on it later.(wireless sheep)
quote:

ORIGINAL: Spooky

Are you sure you are modifying the right code then?
That should be ending the code before you even get to opening the objconn

The response end would have stopped the code in its tracks - you shouldnt have the same error.
Check exactly what file you are modifying and that you are testing the same/ right file.





mar0364 -> RE: Object required: 'objconn' (3/22/2005 17:29:18)

Thanks for sticking with me here. Here is the exact code I'm running. Am I getting something wrong. The error is the same look at line 56
<%
strconnect="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\checkbox\data\rl_company.mdb"
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Confirmation of adding article to Intranet</title>
</head>
<body>
Process the article
<%
	'Declare variable needed
	Dim strInsert
	Dim	strValue
	Dim blnCrticalError
	
	'if an add was requested add a new article to the table.
	
	If Request.Form ("") = "Add" Then
	'start building the SQL string with the required fields
	strInsert = "Insert into tblonsite (article_date,article_text"
	strValues = "Values('"&CStr(Request.Form("txtArticle_date")) &_
				"','" & CStr(Request.Form("txtArticle_text")) & "'"
				
	'Add active if checked
	If Request.Form("") = 1 Then
	'Add the column name to the insert string
	strInsert = strInsert &",article_status"
	'Add true to the value string
	strValue = strValue & ",True"
	End If
	
	response.write strInsert & ") " & strValue & ")" 
	response.end 

	'Create and open the database object 
	Set objConn = server.createobject("ADODB.Connection") 
	objConn.Open strconnect 
	objConn.execute(strInsert & ") " & strValue & ")"),,129 

	
	'Create and open the database object
	'Set objConn = server.createobject("ADODB.Connection")
	'objConn.Open strconnect
	'objConn.execute(strInsert & ") " & strValue & ")"),,129

	'display the insert string
	Response.Write "the following insert string was executed " &_
				   "and the value inserted into the article table.</p>"
	Response.Write strInsert & ") " & strValue & ")"
	
	End If
	
	'Close and clean
line 56	objConn.close
	set objConn = nothing			    	
%>
</body>

</html>



For the heck of it here is the form the info comes from
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Add article to the articles that display on the frontpage.</title>
</head>

<body>
<p>Add article to the articles that display on the frontpage.</p>
<form action="add_action1.asp" method="post" name="addfrm">
<input type="hidden" name="Action" value="Add">
Article Date<br>
<input type="text" name="article_date" size="8"/><br>
Article Text<br>
<textarea cols="50" rows="2" name="article_text"></textarea><br>
Click her if you want the article to appear on the front page. Otherwise it will appear in the article archive.<br>
<input type="checkbox" value="1" name="article_status"><br>
<input type=button name=btnsubmit value=Submit>
</form>
<script language="vbscript">
Sub btnsubmit_onclick()
If Len(addfrm.article_text.value) = 0 Then
	Alert "You must enter text"
addfrm.txtarticle_text.focus
Exit Sub	
End If
Call addfrm.submit()
End Sub
</script>
</body>

</html>




Spooky -> RE: Object required: 'objconn' (3/22/2005 17:32:14)

Ahhh! bingo, its not running that code

If Request.Form ("[whats this??]") = "Add" Then


'Close and clean
objConn.close
set objConn = nothing

End If ' <-- End if should be here




mar0364 -> RE: Object required: 'objconn' (3/22/2005 20:58:20)

OK now we are getting somewhere.

This is now what I get.
Process the article Insert into tblonsite (article_date,article_text) )

Seems like its not geting the values from the request object.

<%
	'Declare variable needed
	Dim strInsert
	Dim	strValue
	Dim blnCrticalError
	
	'if an add was requested add a new article to the table.
	
	If Request.Form ("Action") = "Add" Then
	'start building the SQL string with the required fields
	strInsert = "Insert into tblonsite (article_date,article_text"
	strValues = "Values('"&CStr(Request.Form("Article_date")) &_
				"','" & CStr(Request.Form("Article_text")) & "'"
				
	'Add active if checked
	If Request.Form("article_status") = 1 Then
	'Add the column name to the insert string
	strInsert = strInsert &",article_status"
	'Add true to the value string
	strValue = strValue & ",True"
	End If
	
	response.write strInsert & ") " & strValue & ")" 
	response.end 

	'Create and open the database object 
	Set objConn = server.createobject("ADODB.Connection") 
	objConn.Open strconnect 
	objConn.execute(strInsert & ") " & strValue & ")"),,129 

	
	'Create and open the database object
	'Set objConn = server.createobject("ADODB.Connection")
	'objConn.Open strconnect
	'objConn.execute(strInsert & ") " & strValue & ")"),,129

	'display the insert string
	Response.Write "the following insert string was executed " &_
				   "and the value inserted into the article table.</p>"
	Response.Write strInsert & ") " & strValue & ")"
	
	
	
	'Close and clean
	objConn.close
	set objConn = nothing	
	
	End If    	
%>






BeTheBall -> RE: Object required: 'objconn' (3/22/2005 23:14:05)

Is your form by chance using the GET method (I ask because the one you emailed me did)? If so, change it to POST and see if that resolves the issue.




Spooky -> RE: Object required: 'objconn' (3/22/2005 23:49:36)

At some points you use "strValue" at others, you use "strValues"




mar0364 -> RE: Object required: 'objconn' (3/23/2005 7:17:54)

Its a post.

Thanks!




mar0364 -> RE: Object required: 'objconn' (3/23/2005 8:52:30)

IT'S ALIVE. Outfront the best friend a web person can ever have.

Thanks! It's all about the little things.

Everyone go and have a pint on me!

quote:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Add article to the articles that display on the frontpage.</title>
</head>

<body>
<p>Add article to the articles that display on the frontpage.</p>
<form action="add_action1.asp" method="post" name="addfrm">
<input type="hidden" name="Action" value="Add">
Article Date<br>
<input type="text" name="article_date" size="8"/><br>
Article Text<br>
<textarea cols="50" rows="2" name="article_text"></textarea><br>
Click her if you want the article to appear on the front page. Otherwise it will appear in the article archive.<br>
<input type="checkbox" value="1" name="article_status"><br>
<input type=button name=btnsubmit value=Submit>
</form>
<script language="vbscript">
Sub btnsubmit_onclick()
If Len(addfrm.article_text.value) = 0 Then
Alert "You must enter text"
addfrm.txtarticle_text.focus
Exit Sub
End If
Call addfrm.submit()
End Sub
</script>
</body>

</html>




mar0364 -> RE: Object required: 'objconn' (3/23/2005 14:04:49)

What does the 129 mean at the end of this?

It means adexecutenorecords + adCmdText

Its more efficient when doing updates, as the script doesnt expect data in return

quote:

objConn.execute(strInsert & ") " & strValue & ")"),,129




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.140625