Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 21st, 2007, 03:11 PM
Registered User
 
Join Date: Sep 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please help with Annoying error

Hi everyone,

I have a basic FORM with a text field called username. I am trying to submit the name to my database but get the same irritating error message every time. What am I doing wrong? This is becoming real frustrating.

I will appreciate help so much

Regards
Super007

[u]The error: </u>

Error Type:

ADODB.Recordset (0x800A0E7D)
The connection cannot be used to perform this operation. It is either closed or invalid in this context.
/Formprocess.asp, line 15

Here is my code:


[u]Form.asp</u>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>

<form id="form1" name="form1" method="post" action="Formprocess.asp">

  <p>username <input name="username" type="text" id="username" /></p>

  <p><input type="submit" name="Submit" value="Submit" /></p>
</form>
</body>
</html>


[u]Formprocess.asp</u>

<% Option Explicit %>




<%
Dim objRS, strConnection, strusername

strusername = Request.Form("username")

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\Database\admin.mdb"

Set strConnection = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")

objRS.Open "users", strConnection, adOpenStatic, adLockOptimistic, adCmdTable
objRS.AddNew
objRS("username") = strusername
objRS.Update


objRS.Close
Set objRS = Nothing
%>




 
Old September 21st, 2007, 03:24 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You reuse the connection string variable for the actual connection object:
Code:
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\Database\admin.mdb"

Set strConnection = Server.CreateObject("ADODB.Connection")
You overwrite strConnection with a connection object which then doesn't know anything about the connection string anymore. Try this instead:
Code:
Dim objConnection, objRS, strConnection, strusername        

strusername = Request.Form("username")

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\Database\admin.mdb"

Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.Open strConnection
...
objRS.Open "users", objConnection, adOpenStatic, adLockOptimistic, adCmdTable
Hope this helps,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old September 21st, 2007, 03:39 PM
Registered User
 
Join Date: Sep 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

I feel stupid about the error with the connection object, but now it gives me the following error...

The Microsoft Jet database engine cannot open the file 'C:\Inetpub\wwwroot\Database\admin.mdb'. It is already opened exclusively by another user, or you need permission to view its data.
/formprocess.asp, line 14


My database is not open and it is not READ ONLY.

I will appreciate help once again so much

Regards
Super007

 
Old September 21st, 2007, 03:48 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It's indeed probably not read-only. However, for the web server it appears to be as it is not allowed to write to it. Take a look here for more details:

http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=263

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old September 21st, 2007, 04:14 PM
Registered User
 
Join Date: Sep 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar!

You are my HERO!:D

I cannot thank you enough

Kind Regards
Super007

 
Old September 22nd, 2007, 03:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome. Glad it's working...

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old September 26th, 2007, 12:56 AM
Authorized User
 
Join Date: Dec 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

If till now u r getting problem with access database.

Make the folder to Share which holds the database.
and try again.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Annoying password prompts using ODBC to DB2 d-fxt Access 2 July 1st, 2006 08:18 PM
Extremely annoying VS.Net behavior katsarosj VS.NET 2002/2003 6 April 17th, 2006 09:21 AM
Small (yet annoying) gap gkirk CSS Cascading Style Sheets 2 June 1st, 2005 04:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.