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

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<%@ language="vbscript" %>
<%
sub B3_onclick()
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="C:\Documents and Settings\sridhanj\Desktop\project\logon.mdb"
SQL = "INSERT INTO tblusers ('UID') VALUES (document.loginform.T2.value);"
Conn.Execute(SQL)
Conn.Close
end sub

%>

<title>New Page 1</title>
</head>

<body>
<form name = "loginform">
<h1 align="center">LOGIN</h1>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center">Username:&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="T1" size="20">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p align="center">Password:&nbsp;&nbsp;&nbsp;&nbsp;
<input type="password" name="T2" size="20" maxlength="12">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p align="center">&nbsp;</p>
<p align="center"><input type="submit" value="Submit" name="B3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="Reset" name="B4"></p>
</form>

</body>

</html>

Recommended Answers

All 4 Replies

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

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="">

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 .

Hi,

Please close this thread, as this will help others who will be looking for solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.