export data from asp to .mdb?

Hi

I am currently trying to get a simple data submission asp form to export
data to an access database, this is the code for the contact_insert page

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="Company" content="Kalptaru Infotech Ltd. [www.a2zhelp.com]">
<title>This page was generated using ASP Helper [www.a2zhelp.com]</title>
<style>
<!--
td { font-family: Tahoma; font-size: 8pt; background-color:
#E6F2FF;
border-style: solid; border-width: 1 }
th { font-family: Tahoma; font-size: 8pt; font-weight: bold;
background-color:
#E6E6E6; border: 1px outset #FF9900; }
input { font-family: Tahoma; font-size: 8pt; border: 1px inset
#E6E6E6; }
table { }
-->
</style>
</head>
<body>
<table border="0" cellpadding="2" width="100%">
<tr>
<td colspan="3" width="100%">Adding data to the database</td>
</tr>
<tr>
<td width="10%"></td>
<td width="80%">
<%const DATABASE_NAME="bigbrother.mdb"
dim Con
set Con=server.createobject("ADODB.Connection")
Con.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&
server.mappath(DATABASE_NAME) & ";User Id=Admin;Password="
%>

<%'-------Getting Name
dim Name
Name=Request("Name")
Name=Replace(Name,"'","''")%>
<%if trim(Name)="" then
bHasError=true
sErrMessage=sErrMessage & "<LI> Name cannot be empty."
end if%>
<%'-------Getting Email
dim Email
Email=Request("Email")
Email=Replace(Email,"'","''")%>
<%if trim(Email)="" then
bHasError=true
sErrMessage=sErrMessage & "<LI> Email cannot be empty."
end if%>
<%'-------Getting Query
dim Query
Query=Request("Query")
Query=Replace(Query,"'","''")%>
<%if trim(Query)="" then
bHasError=true
sErrMessage=sErrMessage & "<LI> Query cannot be empty."
end if%>
<%if bHasError then%>
<table><tr><td colspan="2" align="center"
width=100%><%Response.Write("Sorry we cannot proceed because of the following
errors") %></td></tr>
<tr><td colspan=2 width=100%><%response.write
sErrMessage%></td></tr></table>
<%else%>
<%Dim sSQL
sSQL ="insert into [Contact]([Name],[Email],[Query]) values( " & "'" & Name
& "','"&Email&"','"&Query&"')"
con.Execute sSQL
%>
Congratulations!!! Database was successfully updated.
<%End if
%></td>
<td width="10%"></td>
</tr>
<tr>
<td colspan="3" width="100%" bgcolor="#FF9900">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td bgcolor="#E6E6E6">
<p align="center"><font face="Tahoma" size="1"
color="#0000FF"><br>
This
page was automatically generated using Kalptaru Infotech Ltd's ASP
Helper, <br>
the automatic ASP Code generation software.<br>
For more information on how to improve the efficiency and speed of
your ASP Programming and to know more about ASP Helper visit <a
href="http://www.a2zhelp.com">www.a2zhelp.com</a>
or send an email to <a
href="mailto:asphelper [at] a2zhelp.com">asphelper [at] a2zhelp.com<br>
</a>
</font></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

and this is the error message i get:

Technical Information (for support personnel)

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable
query.
/contact_insert.asp, line 65


Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)

Page:
POST 81 bytes to /contact_insert.asp

POST Data:
Name=paul&Email=pen [at] hotmail.com&Query=how+much+is+that+recor d+in+the+window%3F...

Time:
07 March 2006, 15:11:00

any help would be gratefully appreciated

paul
MrPen [ Di, 07 März 2006 16:30 ] [ ID #1218576 ]

Re: export data from asp to .mdb?

Mr Pen wrote:
> Hi
>
> I am currently trying to get a simple data submission asp form to export
> data to an access database, this is the code for the contact_insert page
>
> <html>
> <head>
> <meta http-equiv="Content-Language" content="en-us">
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
> <meta name="ProgId" content="FrontPage.Editor.Document">
> <meta name="Company" content="Kalptaru Infotech Ltd. [www.a2zhelp.com]">
> <title>This page was generated using ASP Helper [www.a2zhelp.com]</title>
> <style>
> <!--
> td { font-family: Tahoma; font-size: 8pt; background-color:
> #E6F2FF;
> border-style: solid; border-width: 1 }
> th { font-family: Tahoma; font-size: 8pt; font-weight: bold;
> background-color:
> #E6E6E6; border: 1px outset #FF9900; }
> input { font-family: Tahoma; font-size: 8pt; border: 1px inset
> #E6E6E6; }
> table { }
> -->
> </style>
> </head>
> <body>
> <table border="0" cellpadding="2" width="100%">
> <tr>
> <td colspan="3" width="100%">Adding data to the database</td>
> </tr>
> <tr>
> <td width="10%"></td>
> <td width="80%">
> <%const DATABASE_NAME="bigbrother.mdb"
> dim Con
> set Con=server.createobject("ADODB.Connection")
> Con.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&
> server.mappath(DATABASE_NAME) & ";User Id=Admin;Password="
> %>
>
> <%'-------Getting Name
> dim Name
> Name=Request("Name")
> Name=Replace(Name,"'","''")%>
> <%if trim(Name)="" then
> bHasError=true
> sErrMessage=sErrMessage & "<LI> Name cannot be empty."
> end if%>
> <%'-------Getting Email
> dim Email
> Email=Request("Email")
> Email=Replace(Email,"'","''")%>
> <%if trim(Email)="" then
> bHasError=true
> sErrMessage=sErrMessage & "<LI> Email cannot be empty."
> end if%>
> <%'-------Getting Query
> dim Query
> Query=Request("Query")
> Query=Replace(Query,"'","''")%>
> <%if trim(Query)="" then
> bHasError=true
> sErrMessage=sErrMessage & "<LI> Query cannot be empty."
> end if%>
> <%if bHasError then%>
> <table><tr><td colspan="2" align="center"
> width=100%><%Response.Write("Sorry we cannot proceed because of the following
> errors") %></td></tr>
> <tr><td colspan=2 width=100%><%response.write
> sErrMessage%></td></tr></table>
> <%else%>
> <%Dim sSQL
> sSQL ="insert into [Contact]([Name],[Email],[Query]) values( " & "'" & Name
> & "','"&Email&"','"&Query&"')"
> con.Execute sSQL
> %>
> Congratulations!!! Database was successfully updated.
> <%End if
> %></td>
> <td width="10%"></td>
> </tr>
> <tr>
> <td colspan="3" width="100%" bgcolor="#FF9900">
> <table border="0" cellpadding="0" cellspacing="0" width="100%">
> <tr>
> <td bgcolor="#E6E6E6">
> <p align="center"><font face="Tahoma" size="1"
> color="#0000FF"><br>
> This
> page was automatically generated using Kalptaru Infotech Ltd's ASP
> Helper, <br>
> the automatic ASP Code generation software.<br>
> For more information on how to improve the efficiency and speed of
> your ASP Programming and to know more about ASP Helper visit <a
> href="http://www.a2zhelp.com">www.a2zhelp.com</a>
> or send an email to <a
> href="mailto:asphelper [at] a2zhelp.com">asphelper [at] a2zhelp.com<br>
> </a>
> </font></td>
> </tr>
> </table>
> </td>
> </tr>
> </table>
> </body>
> </html>
>
> and this is the error message i get:
>
> Technical Information (for support personnel)
>
> Error Type:
> Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
> [Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable
> query.
> /contact_insert.asp, line 65
>
>
> Browser Type:
> Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
>
> Page:
> POST 81 bytes to /contact_insert.asp
>
> POST Data:
> Name=paul&Email=pen [at] hotmail.com&Query=how+much+is+that+recor d+in+the+window%3F...
>
> Time:
> 07 March 2006, 15:11:00
>
> any help would be gratefully appreciated
>
> paul

Where to start....

The error message you are receiving is usually to do with permissions
on the database. The IUSR_machinename account needs read and write
permission on the directory holding the database file.

Second - you are using the obselete ODBC driver. You should be using
the native Jet OLEDB driver instead.

Third - you should be using parameter markers instead of dynamic sql
http://groups-beta.google.com/group/microsoft.public.inetser ver.asp.db/msg/72e36562fee7804e

Or better still saved parameter queries:
http://groups.google.com/group/microsoft.public.inetserver.a sp.db/msg/b3d322b882a604bd

(Those last two links courtesy of Bob Barrows.)

Fourth, your use of the variable Name could cause problems in certain
circumstances. It is a VBScript native keyword.

Frankly, if "ASPHelper" came up with this code, I'd ditch it and learn
ASP properly.

--
Mike Brind
Paxton [ Di, 07 März 2006 17:34 ] [ ID #1218577 ]

Re: export data from asp to .mdb?

"Mr Pen" <MrPen [at] discussions.microsoft.com> wrote in message
news:59876DDE-BE6B-4464-AD42-6CA0F928D61D [at] microsoft.com...
> Hi
>
> I am currently trying to get a simple data submission asp form to export
> data to an access database, this is the code for the contact_insert page
>
> <html>
> <head>
> <meta http-equiv="Content-Language" content="en-us">
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
> <meta name="ProgId" content="FrontPage.Editor.Document">
> <meta name="Company" content="Kalptaru Infotech Ltd. [www.a2zhelp.com]">
> <title>This page was generated using ASP Helper [www.a2zhelp.com]</title>
> <style>
> <!--
> td { font-family: Tahoma; font-size: 8pt; background-color:
> #E6F2FF;
> border-style: solid; border-width: 1 }
> th { font-family: Tahoma; font-size: 8pt; font-weight: bold;
> background-color:
> #E6E6E6; border: 1px outset #FF9900; }
> input { font-family: Tahoma; font-size: 8pt; border: 1px inset
> #E6E6E6; }
> table { }
> -->
> </style>
> </head>
> <body>
> <table border="0" cellpadding="2" width="100%">
> <tr>
> <td colspan="3" width="100%">Adding data to the database</td>
> </tr>
> <tr>
> <td width="10%"></td>
> <td width="80%">
> <%const DATABASE_NAME="bigbrother.mdb"
> dim Con
> set Con=server.createobject("ADODB.Connection")
> Con.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&
> server.mappath(DATABASE_NAME) & ";User Id=Admin;Password="
> %>
>
> <%'-------Getting Name
> dim Name
> Name=Request("Name")
> Name=Replace(Name,"'","''")%>
> <%if trim(Name)="" then
> bHasError=true
> sErrMessage=sErrMessage & "<LI> Name cannot be empty."
> end if%>
> <%'-------Getting Email
> dim Email
> Email=Request("Email")
> Email=Replace(Email,"'","''")%>
> <%if trim(Email)="" then
> bHasError=true
> sErrMessage=sErrMessage & "<LI> Email cannot be empty."
> end if%>
> <%'-------Getting Query
> dim Query
> Query=Request("Query")
> Query=Replace(Query,"'","''")%>
> <%if trim(Query)="" then
> bHasError=true
> sErrMessage=sErrMessage & "<LI> Query cannot be empty."
> end if%>
> <%if bHasError then%>
> <table><tr><td colspan="2" align="center"
> width=100%><%Response.Write("Sorry we cannot proceed because of the
following
> errors") %></td></tr>
> <tr><td colspan=2 width=100%><%response.write
> sErrMessage%></td></tr></table>
> <%else%>
> <%Dim sSQL
> sSQL ="insert into [Contact]([Name],[Email],[Query]) values( " & "'" &
Name
> & "','"&Email&"','"&Query&"')"
> con.Execute sSQL
> %>
> Congratulations!!! Database was successfully updated.
> <%End if
> %></td>
> <td width="10%"></td>
> </tr>
> <tr>
> <td colspan="3" width="100%" bgcolor="#FF9900">
> <table border="0" cellpadding="0" cellspacing="0" width="100%">
> <tr>
> <td bgcolor="#E6E6E6">
> <p align="center"><font face="Tahoma" size="1"
> color="#0000FF"><br>
> This
> page was automatically generated using Kalptaru Infotech Ltd's
ASP
> Helper, <br>
> the automatic ASP Code generation software.<br>
> For more information on how to improve the efficiency and
speed of
> your ASP Programming and to know more about ASP Helper visit
<a
> href="http://www.a2zhelp.com">www.a2zhelp.com</a>
> or send an email to <a
> href="mailto:asphelper [at] a2zhelp.com">asphelper [at] a2zhelp.com<br>
> </a>
> </font></td>
> </tr>
> </table>
> </td>
> </tr>
> </table>
> </body>
> </html>
>
> and this is the error message i get:
>
> Technical Information (for support personnel)
>
> Error Type:
> Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
> [Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable
> query.
> /contact_insert.asp, line 65
>
>
> Browser Type:
> Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
>
> Page:
> POST 81 bytes to /contact_insert.asp
>
> POST Data:
>
Name=paul&Email=pen [at] hotmail.com&Query=how+much+is+that+recor d+in+the+window%
3F...
>
> Time:
> 07 March 2006, 15:11:00
>
> any help would be gratefully appreciated
>
> paul

Basically, you're using the wrong "cursor".
http://www.aspfaq.com/show.asp?id 62

Also, "Name" is a reserved word.
It should not be used as the name of a field or variable.

It's not practice to mix CSS and <font> tags.

The link http://www.aspfaq.com/show.asp?id=2126 receommends using
"Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Data Source="
instead of
"DRIVER={Microsoft Access Driver (*.mdb)};User Id=Admin;Password=";DBQ="

Also, you should use Server.MapPath() to resolve your databases' path.

"Option Explicit" should be used to ensure that all variables are declared.


Perhaps this untested rewrite will help. Watch for word-wrap.

<% [at] Language="VBScript" %>
<% Option Explicit
'*
Const cMDB = "bigbrother.mdb"
Const cDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database
Password=;Data Source="
'*
Const adCmdTable = &H0002
Const adLockBatchOptimistic = 4
Const adOpenKeySet = 1
'*
Dim sERR
sERR = ""
Dim sMSG
'*
Dim sName
sName = Trim(Request("Name"))
Dim sEmail
sEmail = Trim(Request("Email"))
Dim sQuery
sQuery = Trim(Request("Query"))
'*
If sName = "" Then
sERR = sERR & "<li> Name cannot be empty."
End If
If sEmail = "" Then
sERR = sERR & "<li> Email cannot be empty."
End If
If sQuery = "" Then
sERR = sERR & "<li> Query cannot be empty."
End If
'*
If sERR <> "" Then
sMSG = "<table><tr><td align='center' width='100%'>"
sMSG = sMSG & "Sorry, we cannot proceed because of the following
errors"
sMSG = sMSG & "</td></tr><tr><td width='100%'>"
sMSG = sMSG & sERR
sMSG = sMSG & "</td></tr></table>"
Else
Dim oADO
Set oADO = Server.CreateObject("ADODB.Connection")
oADO.Open cDSN & Server.MapPath(cMDB)
Dim oRST
Set oRST = Server.CreateObject("ADODB.Recordset")
oRST.Open "[Contact]", oADO, adOpenKeySet, adLockOptimistic,
adCmdTable
oRST.AddNew
oRST("Name").Value = Replace(sName,"'","''")
oRST("Email").Value = Replace(sEmail,"'","''")
oRST("Query").Value = Replace(sQuery,"'","''")
oRST.Update
oRST.Close
Set oRST = Nothing
oADO.Close
Set oADO = Nothing
sMSG = "Congratulations!!! Database was successfully updated."
End If
%>
<html>
<head>
<title>This page was generated using ASP Helper [www.a2zhelp.com]</title>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="Company" content="Kalptaru Infotech Ltd. [www.a2zhelp.com]">
<style type="text/css">
td { font-family: Tahoma;
font-size: 8pt;
background-color: #E6F2FF;
border-style: solid;
border-width: 1;
}
th { font-family: Tahoma;
font-size: 8pt;
font-weight: bold;
background-color: #E6E6E6;
border: 1px outset #FF9900;
}
input { font-family: Tahoma;
font-size: 8pt;
border: 1px inset #E6E6E6;
}
table { }
</style>
</head>
<body>
<table border="0" cellpadding="2" width="100%">
<tr>
<td colspan="3" width="100%">Adding data to the database</td>
</tr>
<tr>
<td width="10%"> </td>
<td width="80%"><%=sMSG%></td>
<td width="10%"> </td>
</tr>
<tr>
<td bgcolor="#FF9900" colspan="3" width="100%">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center" bgcolor="#E6E6E6">
<font face="Tahoma" size="1" color="#0000FF">
<br>
This page was automatically generated using Kalptaru Infotech Ltd's
ASP Helper,
<br>
the automatic ASP Code generation software.
<br>
For more information on how to improve the efficiency and speed of
your ASP Programming and to know more about ASP Helper visit
www.a2zhelp.com
or send an email to
asphelper [at] a2zhelp.com
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
McKirahan [ Di, 07 März 2006 17:41 ] [ ID #1218578 ]

Re: export data from asp to .mdb?

Mr Pen wrote:
>
> Error Type:
> Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
> [Microsoft][ODBC Microsoft Access Driver] Operation must use an
> updateable query.
> /contact_insert.asp, line 65
>
http://www.aspfaq.com/show.asp?id 62

General recommendations:
http://www.aspfaq.com/show.asp?id=2126
http://groups-beta.google.com/group/microsoft.public.inetser ver.asp.db/msg/72e36562fee7804e
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&c2coff=1& selm=eHYxOyvaDHA.4020%40tk2msftngp13.phx.gbl

HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
reb01501 [ Di, 07 März 2006 17:48 ] [ ID #1218579 ]
Webserver » microsoft.public.inetserver.asp.db » export data from asp to .mdb?

Vorheriges Thema: Option Box Images??
Nächstes Thema: Using Sql Server 2005 w/ ASP 2.0, attaching a .mdf