User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 403,519 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,807 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Views: 659 | Replies: 4
Reply
Join Date: Jun 2008
Posts: 2
Reputation: anjalis is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
anjalis anjalis is offline Offline
Newbie Poster

Trouble connecting to Access database

  #1  
Jul 2nd, 2008
I am trying to connect my login page to an access database. Right now I am simply storing the values inside the database .I am having trouble connecting to the databse itself. Below is the code that I have written using VBScript. What am I doing wrong? ...Thanks in advance

  1.  
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  5. <%@ language="vbscript" %>
  6. <%
  7. sub B3_onclick()
  8. Set Conn = Server.CreateObject("ADODB.Connection")
  9. Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="C:\Documents and Settings\sridhanj\Desktop\project\logon.mdb"
  10. SQL = "INSERT INTO tblusers ('UID') VALUES (document.loginform.T2.value);"
  11. Conn.Execute(SQL)
  12. Conn.Close
  13. end sub
  14.  
  15. %>
  16.  
  17. <title>New Page 1</title>
  18. </head>
  19.  
  20. <body>
  21. <form name = "loginform">
  22. <h1 align="center">LOGIN</h1>
  23. <p align="center">&nbsp;</p>
  24. <p align="center">&nbsp;</p>
  25. <p align="center">&nbsp;</p>
  26. <p align="center">&nbsp;</p>
  27. <p align="center">Username:&nbsp;&nbsp;&nbsp;&nbsp;
  28. <input type="text" name="T1" size="20">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  29. </p>
  30. <p align="center">Password:&nbsp;&nbsp;&nbsp;&nbsp;
  31. <input type="password" name="T2" size="20" maxlength="12">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  32. </p>
  33. <p align="center">&nbsp;</p>
  34. <p align="center"><input type="submit" value="Submit" name="B3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  35. <input type="reset" value="Reset" name="B4"></p>
  36. </form>
  37.  
  38. </body>
  39.  
  40. </html>
  41.  
Last edited by peter_budo : Jul 7th, 2008 at 7:22 am. Reason: Code tag correction, tags are [code]&[/code] not <code>with</code>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2008
Posts: 2
Reputation: veenum2 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
veenum2 veenum2 is offline Offline
Newbie Poster

Re: Trouble connecting to Access database

  #2  
Jul 4th, 2008
Well what i suggest is that u comment ur code where ur closing ur connection and then try if that works or not

like this
'Connection.close
try this

Another thing is that try saving your database to somewhere else
like in C Drive and then use the correct path
another option is that u can create a DSN and then open the connection rather than using a DSN Less connection what ur doing here
hope u know how to do that you need to go to control panel > Administrative tools > ODBC then select the SYstem DSN tab and then select ADD on the right side then a message box will appear saying Select a driver for which u want to setup the data source - then in the NAME select Microsoft driver (*.mdb) then Type ur DSN Name here and select the database that is locate ur DB where it is located in the Computer System for example ur DB is in C:/ProjectsDB so u just browse and locate it here ok and then press ok

then in VB script
ur codewill look like this if u want to use a DSN Connection
for example

set mycon = Server.CreateObject("ADODB.Connection")
myDSN = " " here ull put ur Database DSN which u will make

then simply open ur dsn and con

myCon.open myDSN
and then u can execute ur query

like
Reply With Quote  
Join Date: Jun 2008
Location: Delhi
Posts: 119
Reputation: vicky_rawat is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 15
vicky_rawat's Avatar
vicky_rawat vicky_rawat is offline Offline
Junior Poster

Re: Trouble connecting to Access database

  #3  
Jul 6th, 2008
Hi,

I found two things in your code that, I think are causing problem.
1. b3_onclick: events are not called like this in asp.
Moreever, what you are trying to do is clicking on submit Button will make you conect to database and then execute something, right?

What you have written is a VB code where everyting is on client side. but here in ASP things are not like VB.

you will first need to do something.

Put your code and mdb file in inetpub/wwwroot folder. then use the following code

<%
if request.servervariables("HTTP_METHOD") = "POST" then
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&server.mappath("logon.mdb")
SQL = "INSERT INTO tblusers ('UID') VALUES ("&request.form("T1")&");"
Conn.Execute(SQL)
Conn.Close
end if

%>

also the form should be defind as
<form method=post name = "loginform" action="">
Vivek Rawat
Keep solving complexities.
Reply With Quote  
Join Date: Jun 2008
Posts: 2
Reputation: anjalis is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
anjalis anjalis is offline Offline
Newbie Poster

Re: Trouble connecting to Access database

  #4  
Jul 6th, 2008
Thanks a lot veenum2 and vicky_rawat for replying..........I was able to get the connection working . I stored the folders as suggested in inetpub/wwwroot folder and was able to connect to the database. I also had the problem with submitting the form which was also solved .Thanks a ton .
Reply With Quote  
Join Date: Jun 2008
Location: Delhi
Posts: 119
Reputation: vicky_rawat is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 15
vicky_rawat's Avatar
vicky_rawat vicky_rawat is offline Offline
Junior Poster

Re: Trouble connecting to Access database

  #5  
Jul 8th, 2008
Hi,

Please close this thread, as this will help others who will be looking for solution.
Vivek Rawat
Keep solving complexities.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP Forum

All times are GMT -4. The time now is 1:07 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC