connecting to database

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: connecting to database

  1. #1
    Join Date
    Dec 1969
    Posts
    28

    Default connecting to database

    This is the code that I am using. <BR><BR><BR>&#060;%@ language=VBScript %&#062;<BR>&#060;% response.buffer = true %&#062;<BR>&#060;!--#include virtual="adovbs.inc"--&#062;<BR>&#060;%<BR> Dim objconn,objVI,intVisitor<BR><BR> intVisitor=request("Visitor")<BR> if (intVisitor="") then<BR> response.redirect "logon.html"<BR> end if<BR><BR> set objconn = server.createobject("ADODB.connection")<BR> objconn.connectionstring ="DRIVER={Microsoft Access Driver (*.mdb)};"&_<BR> "DBQ=C:InetpubwwwrootStudent.mdb"<BR>objconn.open< BR><BR>set objVI=server.createobject("ADODB.Recordset")<BR>ob jVI.open "VisitorInformation",objconn,adlockOptimistic,adcm dtable<BR><BR>This is the error message that I am getting.<BR><BR><BR>Microsoft OLE DB Provider for ODBC Drivers error &#039;80040e14&#039; <BR><BR>[Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected &#039;DELETE&#039;, &#039;INSERT&#039;, &#039;PROCEDURE&#039;, &#039;SELECT&#039;, or &#039;UPDATE&#039;. <BR><BR>/process_logon.asp, line 18 <BR><BR><BR>I don&#039;t understand why this doesn&#039;t work. I cut and pasted this exact information from another working asp page. The only thing that I changed where the names. The error is occuring on the last line of code.

  2. #2
    Fritz Guest

    Default RE: connecting to database

    This works on another page? What does it do? Because it certainly doesn&#039;t &#039;DELETE&#039;, &#039;INSERT&#039;, &#039;PROCEDURE&#039;, &#039;SELECT&#039;, or &#039;UPDATE&#039;<BR><BR>objVI.open "VisitorInformation",objconn,adlockOptimistic,adcm dtable <BR><BR>What do you want to do with "VisitorInformation" besides open it?<BR>. <BR><BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    28

    Default RE: connecting to database

    What I meant about working on another page is the connecting to the database. But here is the rest of the code. All I want it to do is count the number of vists. That is all that it needs to do. <BR><BR><BR> do while not (objVI.eof or bolFound)<BR> if (strcomp(objVI("Visitor"),intVistor,vbTextCompare) =0) then<BR> bolFound=true<BR> else<BR> objPI.movenext<BR> end if<BR> loop<BR><BR> if bolFound then<BR> response.write bolFound<BR> objVI("Visits")=objVI("Visits") + 1<BR> else<BR> response.redirect "new_visitor.html"<BR> end if<BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    2,958

    Default RE: connecting to database

    What I think fritz is saying is that once you open the db what are you going to do with it? Are you going to read the info in it, update it, delete it or add to it? The code you are showing does none of the above. If you have field in the db that keeps track of the number of visits you have to open the db read the number that is in there, add 1 to it, update it, and then close the db.


  5. #5
    Fritz Guest

    Default Yes, exactly!

    ...

  6. #6
    Join Date
    Dec 1969
    Posts
    28

    Default RE: connecting to database

    I understand the point that you are trying to make, but I didn&#039;t cut and past the whole script what I left out was : <BR><BR>objVI.update<BR> <BR>objVI.Close<BR>set objVI=nothing<BR> <BR>objconn.close<BR>set objconn=nothing<BR>response.redirect "logon.html"<BR>%&#062;<BR><BR><BR>The problem is I can&#039;t get past the line :<BR><BR> objVI.open "Visitor Information",objconn,adlockOptimistic,adcmdtable<B R><BR>because I get this error : <BR><BR>Microsoft OLE DB Provider for ODBC Drivers error &#039;80040e14&#039; <BR><BR>[Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected &#039;DELETE&#039;, &#039;INSERT&#039;, &#039;PROCEDURE&#039;, &#039;SELECT&#039;, or &#039;UPDATE&#039;. <BR><BR>/process_logon.asp, line 18 <BR><BR><BR>I don&#039;t understand why it is causing this error on this line. I have used this exact technique for opening up tables in Acess databases from previous projects. Why is it giving me this error now?<BR><BR>

  7. #7
    Join Date
    Dec 1969
    Posts
    2,958

    Default RE: connecting to database

    You do not understand the point! <BR><BR><BR>objVI.update ?????<BR><BR>Update what to what ?????<BR><BR>This error is quite literal.<BR>Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected &#039;DELETE&#039;, &#039;INSERT&#039;, &#039;PROCEDURE&#039;, &#039;SELECT&#039;, or &#039;UPDATE&#039;. <BR><BR>Your update statement is invalid! You not telling it what to update anywhere! Simply putting the word update in the code won&#039;t cut it!<BR><BR>objVI is your connection desiganation you can&#039;t update it! You have to open the db, tell it which table in the db and then the field to update.<BR><BR>This code may have come from a different page that does work but you MUST have altered it. The way you have this you will continue to get errors until you do what we have been tryign to tell you to do.

  8. #8
    Join Date
    Dec 1969
    Posts
    28

    Default RE: connecting to database

    Maybe the problem is that I have spread the complete code across several posts. Here is it in the entirety :<BR><BR>&#060;%@ language=VBScript %&#062;<BR>&#060;% response.buffer = true %&#062;<BR>&#060;!--#include virtual="adovbs.inc"--&#062;<BR>&#060;%<BR> Dim objconn,objVI,intVisitor<BR><BR> intVisitor=request("Visitor")<BR> if (intVisitor="") then<BR> response.redirect "logon.html"<BR> end if<BR><BR> set objconn = server.createobject("ADODB.connection")<BR> objconn.connectionstring ="DRIVER={Microsoft Access Driver (*.mdb)};"&_<BR> "DBQ=C:InetpubwwwrootVisitors.mdb"<BR> objconn.open<BR><BR> set objVI=server.createobject("ADODB.Recordset")<BR> objVI.open "Visitor Information",objconn,adlockOptimistic,adcmdtable<B R> <BR> do while not (objVI.eof or bolFound)<BR> if (strcomp(objVI("Visitor"),intVistor,vbTextCompare) =0) then<BR> bolFound=true<BR> else<BR> objPI.movenext<BR> end if<BR> loop<BR><BR> if bolFound then<BR> response.write bolFound<BR> objVI("Visits")=objVI("Visits") + 1<BR> else<BR> response.redirect "new_visitor.html"<BR> end if<BR> <BR> objVI.update<BR> <BR> objVI.Close<BR> set objVI=nothing<BR><BR> <BR> objconn.close<BR> set objconn=nothing<BR> &#039;response.redirect "logon.html"<BR>%&#062; <BR><BR><BR>Here is all that I am trying to do, <BR>get the visitor number that comes throught the querystring, <BR>if it is empty go back to logon page<BR><BR>if not empty check to see if in database, <BR> if in database add one to number of visits<BR> if not in database go to new vistor page<BR><BR>I find ASP to be quick and easy to use (most of the time) I have been reassigned to devolop web interfaces to alot of database apps that my department runs. (this is not what I was hired to do) I find connecting to the database to be my only problem, because I haven&#039;t ever read anything that explains completely the underlying priciple and technique of the physical connection. I only find in tutorials how to cut and paste the information to make the connection. Maybe if I knew the underlying nuts and bolts, I could understand the error messages that I get better. Maybe you have a good book that explains all of the stuff that normal people don&#039;t want to know.

  9. #9
    Fritz Guest

    Default RE: connecting to database

    Your connection is NOT the problem. Instead of:<BR>objVI.open "VisitorInformation",objconn,adlockOptimistic,adcm dtable <BR>You need something like:<BR>objVI.open "Select Visitor from VisitorInformation where ........",objconn,adlockOptimistic,adcmdtable <BR> <BR> <BR> <BR>

  10. #10
    Join Date
    Dec 1969
    Posts
    2,958

    Default RE: connecting to database

    Why not simplify this whole process.<BR><BR>&#060;%<BR>strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Visitor.mdb")<BR><BR>set conn = server.createobject("adodb.connection")<BR>conn.op en strconn<BR><BR>set rs = server.createobject("adodb.recordset")<BR><BR>Visi tor = Request("Visitor")<BR><BR>sqlstmt = "UPDATE Visitor_Information"<BR>sqlstmt = sqlstmt & " SET Visits = Visits + 1"<BR>sqlstmt = sqlstmt & " WHERE Visitor=&#039;"& Visitor &"&#039;"<BR>Set rs = conn.execute(sqlstmt)<BR>If oRs.EOF Then<BR>Response.Redirect("logon.html")<BR>End If<BR>Set conn = Nothing<BR><BR>End If<BR>%&#062;<BR><BR>&#062;. (this is not what I was hired to do) I find connecting to the database to be my only problem<BR>Maybe you have a good book that explains all of the stuff that normal people don&#039;t want to know.<BR><BR>Connecting to a db is NOT your only problem. We don&#039;t care what you work issues are. Being snide when you need help shows a lack of manners and good judgement. Looks like you need to know this so I guess you need to find a book that explains all of the stuff that people who need help must know. While your at the book store pick one up on ettiquette as well.<BR><BR>Good luck.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •