|
 |
asp_databases thread: Inserting a record into Access database
Message #1 by "Grant I" <giswim1@a...> on Mon, 25 Jun 2001 17:07:53
|
|
OK folks, thank you for reading my previous post. I was able to resolve
the issue about an hour after I posted it, so that was good. Now, though
I have a new problem (*sigh*) Now that I'm able to let users search the
DB, I also need to allow them to edit/add records to the db. Right now
I'm working on the adding portion. When I try to add the record, I get an
error message telling me that either the database or the object is read-
only. However, I made sure the database wasn't read-only in the
properties dialog on the server. I assume this sets permissions for the
file (if there is something else I need to do for that, could you let me
know?). As for the object (a record set I guess), I'm pretty sure I did
that right as well. My code is below. Thank you all for reading this and
helping me out!
-----------
>-My Code-<
-----------
<!--#include file="adovbs.inc"-->
<%
' Declare variables and open a connection to the database
Dim objConn, objRS, strOut
Dim ConnectionString, strCN
Dim strPH, bugID, descrip
Set objConn = Server.CreateObject("ADODB.Connection")
ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);"
ConnectionString = ConnectionString & "DBQ=" & Server.MapPat("mydb.mdb")
objConn.Open ConnectionString
set objRS= Server.CreateObject ("ADODB.Recordset")
if Request.Form("bugrep") <> "" then
objRS.CursorLocation = adUseServer
objRS.CursorType = adOpenDynamic
objRS.LockType = adLockOptimistic
objRS.Open "rd_issues", objConn, , , adCmdTable
' Add data to current record set
objRS.AddNew
descrip = Trim(Request.Form("bugrep"))
objRS("Description") = descrip
objRS("Date_Reported") = Request.Form("date")
objRS("Category") = Request.Form("category")
' Update record set and database, and report bug ID
objRS.Update
bugID = objRS("ID")
Response.Write ("Your issue has been reported. The corresponding
ID number is ")
Response.Write (bugID) & ". <BR><BR>"
%>
<a href="index.html"> Return to the Research Desktop main page </a>
<%
objRS.Close
else
%>
<script LANGUAGE="JavaScript">
alert("Please enter a description of the problem you are
experiencing")
history.back()
</script>
<%
end if
%>
Message #2 by "Peter Foti (PeterF)" <PeterF@S...> on Mon, 25 Jun 2001 12:20:09 -0400
|
|
Assuming that you copied and pasted your code (and did not type it into
the email you sent), I believe your problem is a simple typo:
ConnectionString =3D ConnectionString & "DBQ=3D" &
Server.MapPat("mydb.mdb")
Should be:
ConnectionString =3D ConnectionString & "DBQ=3D" &
Server.MapPath("mydb.mdb")
Hope this helps.
-Peter
> -----Original Message-----
> From: Grant I [mailto:giswim1@a...]
> Sent: Monday, June 25, 2001 5:08 PM
> To: ASP Databases
> Subject: [asp_databases] Inserting a record into Access database
>
>
> OK folks, thank you for reading my previous post. I was able
> to resolve
> the issue about an hour after I posted it, so that was good.
> Now, though
> I have a new problem (*sigh*) Now that I'm able to let users
> search the
> DB, I also need to allow them to edit/add records to the db.
> Right now
> I'm working on the adding portion. When I try to add the
> record, I get an
> error message telling me that either the database or the
> object is read-
> only. However, I made sure the database wasn't read-only in the
> properties dialog on the server. I assume this sets
> permissions for the
> file (if there is something else I need to do for that, could
> you let me
> know?). As for the object (a record set I guess), I'm pretty
> sure I did
> that right as well. My code is below. Thank you all for
> reading this and
> helping me out!
>
> -----------
> >-My Code-<
> -----------
>
> <!--#include file=3D"adovbs.inc"-->
> <%
> ' Declare variables and open a connection to the database
> Dim objConn, objRS, strOut
> Dim ConnectionString, strCN
> Dim strPH, bugID, descrip
>
> Set objConn =3D Server.CreateObject("ADODB.Connection")
>
> ConnectionString =3D "DRIVER=3DMicrosoft Access Driver (*.mdb);"
> ConnectionString =3D ConnectionString & "DBQ=3D" &
> Server.MapPat("mydb.mdb")
> objConn.Open ConnectionString
>
> set objRS=3D Server.CreateObject ("ADODB.Recordset")
>
> if Request.Form("bugrep") <> "" then
> objRS.CursorLocation =3D adUseServer
> objRS.CursorType =3D adOpenDynamic
> objRS.LockType =3D adLockOptimistic
> objRS.Open "rd_issues", objConn, , , adCmdTable
>
> ' Add data to current record set
> objRS.AddNew
> descrip =3D Trim(Request.Form("bugrep"))
> objRS("Description") =3D descrip
> objRS("Date_Reported") =3D Request.Form("date")
> objRS("Category") =3D Request.Form("category")
> =09
> ' Update record set and database, and report bug ID
> objRS.Update
> bugID =3D objRS("ID")
> Response.Write ("Your issue has been reported. The
> corresponding
> ID number is ")
> Response.Write (bugID) & ". <BR><BR>"
> %>
> <a href=3D"index.html"> Return to the Research Desktop
> main page </a>
> <%
> objRS.Close
> else=09
> %>
> <script LANGUAGE=3D"JavaScript">
> alert("Please enter a description of the
> problem you are
> experiencing")
> history.back()
> </script>
> <%
> end if
> %>
>
Message #3 by "Jay" <jtienor@m...> on Mon, 25 Jun 2001 11:13:18 -0500
|
|
Did you make sure that the IUSR_'MachineName' account has access to the
file. This error normally occurs when the web account mentioned previously
has not been given access to the database.
Hope this helps,
Jay
----------------------------------------------------------
Jason L. Tienor
Interactive SolutionZ, LLC
jtienor@i...
xxx.xxx.xxxx
----- Original Message -----
From: "Grant I" <giswim1@a...>
To: "ASP Databases" <asp_databases@p...>
Sent: Monday, June 25, 2001 5:07 PM
Subject: [asp_databases] Inserting a record into Access database
> OK folks, thank you for reading my previous post. I was able to resolve
> the issue about an hour after I posted it, so that was good. Now, though
> I have a new problem (*sigh*) Now that I'm able to let users search the
> DB, I also need to allow them to edit/add records to the db. Right now
> I'm working on the adding portion. When I try to add the record, I get an
> error message telling me that either the database or the object is read-
> only. However, I made sure the database wasn't read-only in the
> properties dialog on the server. I assume this sets permissions for the
> file (if there is something else I need to do for that, could you let me
> know?). As for the object (a record set I guess), I'm pretty sure I did
> that right as well. My code is below. Thank you all for reading this and
> helping me out!
>
Message #4 by "Tomm Matthis" <matthis@b...> on Mon, 25 Jun 2001 12:28:02 -0400
|
|
Make sure the IUSR_xxx account has create/delete access on the
*directory* where the .MDB file resides.
The IUSR_xxx account needs to be able to create/delete the .LDB (lock
file) for the access database.
Let me know if that works for ya.
-- Tomm
> -----Original Message-----
> From: Grant I [mailto:giswim1@a...]
> Sent: Monday, June 25, 2001 5:08 PM
> To: ASP Databases
> Subject: [asp_databases] Inserting a record into Access database
>
>
> OK folks, thank you for reading my previous post. I was able to
resolve
> the issue about an hour after I posted it, so that was good. Now,
though
> I have a new problem (*sigh*) Now that I'm able to let users search
the
> DB, I also need to allow them to edit/add records to the db. Right
now
> I'm working on the adding portion. When I try to add the record,
> I get an
> error message telling me that either the database or the object is
read-
> only. However, I made sure the database wasn't read-only in the
> properties dialog on the server. I assume this sets permissions for
the
> file (if there is something else I need to do for that, could you let
me
> know?). As for the object (a record set I guess), I'm pretty sure I
did
> that right as well. My code is below. Thank you all for reading
> this and
> helping me out!
>
Message #5 by "Grant I" <giswim1@a...> on Mon, 25 Jun 2001 17:48:40
|
|
Once again, I figured it out on my own... maybe I should wait to post for
another hour from now on. Obviously 2 isn't enough :P
> OK folks, thank you for reading my previous post. I was able to resolve
> the issue about an hour after I posted it, so that was good. Now,
though
> I have a new problem (*sigh*) Now that I'm able to let users search the
> DB, I also need to allow them to edit/add records to the db. Right now
> I'm working on the adding portion. When I try to add the record, I get
an
> error message telling me that either the database or the object is read-
> only. However, I made sure the database wasn't read-only in the
> properties dialog on the server. I assume this sets permissions for the
> file (if there is something else I need to do for that, could you let me
> know?). As for the object (a record set I guess), I'm pretty sure I did
> that right as well. My code is below. Thank you all for reading this
and
> helping me out!
>
> -----------
> >-My Code-<
> -----------
>
> <!--#include file="adovbs.inc"-->
> <%
> ' Declare variables and open a connection to the database
> Dim objConn, objRS, strOut
> Dim ConnectionString, strCN
> Dim strPH, bugID, descrip
>
> Set objConn = Server.CreateObject("ADODB.Connection")
>
> ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);"
> ConnectionString = ConnectionString & "DBQ=" & Server.MapPat("mydb.mdb")
> objConn.Open ConnectionString
>
> set objRS= Server.CreateObject ("ADODB.Recordset")
>
> if Request.Form("bugrep") <> "" then
> objRS.CursorLocation = adUseServer
> objRS.CursorType = adOpenDynamic
> objRS.LockType = adLockOptimistic
> objRS.Open "rd_issues", objConn, , , adCmdTable
>
> ' Add data to current record set
> objRS.AddNew
> descrip = Trim(Request.Form("bugrep"))
> objRS("Description") = descrip
> objRS("Date_Reported") = Request.Form("date")
> objRS("Category") = Request.Form("category")
>
> ' Update record set and database, and report bug ID
> objRS.Update
> bugID = objRS("ID")
> Response.Write ("Your issue has been reported. The corresponding
> ID number is ")
> Response.Write (bugID) & ". <BR><BR>"
> %>
> <a href="index.html"> Return to the Research Desktop main page </a>
> <%
> objRS.Close
> else
> %>
> <script LANGUAGE="JavaScript">
> alert("Please enter a description of the problem you are
> experiencing")
> history.back()
> </script>
> <%
> end if
> %>
|
|
 |