Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 3rd, 2004, 03:46 AM
hdekretser hdekretser is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 hdekretser User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old October 3rd, 2004, 09:32 AM
Memnoch's Avatar
Memnoch Memnoch is online now
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 7 h 3 m 32 sec
Reputation Power: 469
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
%>

Reply With Quote
  #3  
Old October 3rd, 2004, 01:44 PM
hdekretser hdekretser is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 hdekretser User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old October 19th, 2004, 11:03 AM
hdekretser hdekretser is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 hdekretser User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:
Originally Posted by Memnoch
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
%>

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Insert into Access db with ASP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT