| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Insert into Access db with ASP
I've a very simple test script but it doesn't seem to be working. Can anyone tell me if my script looks right?
I'm trying to write to an Access 2000 database using ASP. I'm not getting an error message but I'm also not managing to insert my information to the database: <% 'define variables dim Referer dim ShortReferer dim Link 'call in the link they want to go to Link = request.querystring("Venue") 'call in the page they've come from Referer=request.servervariables("http_referer") ShortReferer = Mid(Referer, 25) 'initialise the database variables dim conn, strsql, rsuser, strMDBPath set conn=server.createobject("ADODB.Connection") set rsuser=server.createobject("ADODB.Recordset") 'Connect to the database strMDBpath = Server.MapPath("links.mdb") conn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & strMDBPath On Error Resume Next 'write to the database strsql = "INSERT INTO tblLinkTracker (Link, ShortReferer, Time) VALUES ('" & Link & "', '" & ShortReferer & "', '" & Now() & "')" rsuser.open strsql,conn,1,2 'close database rsuser.close conn.close set rsuser=nothing set conn = nothing %> Thank you H |
|
#2
|
||||
|
||||
|
1) Check to see that you are making a connection to the database.
2) Response.write your sql statement to confirm it is correct. 3) Run the sql statement within Access to verify it will work. Hint: Alot of you code is unnecessary, just try the code below. You don't need a recordset object when running INSERT, UPDATE or DELETE statements, since these commands do not return any records. Code:
<%
'define variables
dim Referer
dim ShortReferer
dim Link
dim conn, strsql, strMDBPath
'call in the link they want to go to
Link = Request.QueryString("Venue")
'call in the page they've come from
Referer = Request.ServerVariables("HTTP_REFERER")
ShortReferer = Mid(Referer, 25)
Set conn = Server.CreateObject("ADODB.Connection")
'Connect to the database
strMDBpath = Server.MapPath("links.mdb")
conn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & strMDBPath
'On Error Resume Next
'write to the database
strSql = "INSERT INTO tblLinkTracker (Link, ShortReferer, Time) VALUES ('" & Link & "', '" & ShortReferer & "', #" & Now() & "#)"
conn.Execute(strSql)
'close database
conn.close
Set conn = nothing
%>
|
|
#3
|
|||
|
|||
|
That's great - you solved my problem and I can go on developing the next part of my script now. I can see the differences you've made but don't quite understand why yours works here and my old one doesn't. I've used my old one on the same site many times and I'd only made a few changes here to names etc. Anyway, I'm just pleased you've got it working for me.
This is the first time I've used the forum and I'm very impressed with how quick a response was posted. Thanks again. |
|
#4
|
|||
|
|||
|
As I said at the time, your help was excellent. However, I'm having a problem getting the script to work if my link is in an html email. I don't understand why.
My href in the HTML email is something like: http://www.mydomain.com/mainfolder/linktracker.asp?link=traking-id instead of writing to the database and re-directing them I get a 500 error with the above address in the address bar. (If I take out the code referring to the database connection the redirection works fine). If I call my HTML email up as a web page the redirection and writing to the database works again. I've also tried copying and pasting the link from the web page into a browser and the same problem happens> Do I need a different approach? Best wishes Hans Quote:
|
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Insert into Access db with ASP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|