Hello All,

I want to store data into MS Access database without using DSN (Data Source Name). For his I have done the coding:-

<% dim stud1
set stud1=server.createobject("adodb.connection") 
stud1.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("amitdatabase.mdb")  
%>
<% dim stud2,stud3  
set stud2=server.createobject("ADODB.Recordset")
stud3 = "SELECT tblComments.Name, tblComments.Comments FROM tblComments;"  
stud2.CursorType = 2 
stud2.lockType = 2 

stud1.open stud2,stud3
%>
<%
stud2.addnew
stud2("firstname")=request.form("one")
stud2("lastname")=request.form("two")
stud2("email")=request.form("three")
stud2("username")=request.form("four")
stud2("password")=request.form("five")
stud2.update
%>

Using this coding I am unable to send data to database from the Form. And I also do not getting any error messages.

Anyone please help me to solve this problem.

Thanks

Dani AI

Generated

Quick diagnosis and what to check first

The most likely causes are: the recordset you open does not contain the columns you try to write, the recordset is read-only because of cursor/SELECT choices, or the web process lacks filesystem permissions on the .mdb so writes silently fail. was right to point out the correct order when opening a Recordset, and correctly stressed opening the Connection first and closing objects afterwards — those are necessary but not sufficient fixes.

Concrete checklist and safer alternatives

  • Confirm the HTML form uses the same input names and POST method that your server code reads.
  • Make sure the SQL you open contains the exact columns you intend to update if you use Recordset.AddNew. If it doesn’t, AddNew cannot populate those fields.
  • If you need to insert new rows, prefer a parameterized INSERT via ADODB.Command (faster, avoids read-only issues and SQL injection).
  • Ensure the connection is opened before opening a recordset and use an updateable cursor/lock (or use INSERT).
  • Check filesystem permissions: the IIS account (IIS_IUSRS / NETWORK SERVICE depending on version) must have modify/write to the .mdb.

Example pattern (parameterized INSERT and simple error check)

<%
On Error Resume Next
Dim conn, cmd
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "<your connection string here>"

Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandText = "INSERT INTO tblComments (firstname,lastname,email,username,[password]) VALUES (?, ?, ?, ?, ?)"
cmd.CommandType = adCmdText

cmd.Parameters.Append cmd.CreateParameter("p1", adVarChar, adParamInput, 50, Request.Form("one"))
cmd.Parameters.Append cmd.CreateParameter("p2", adVarChar, adParamInput, 50, Request.Form("two"))
cmd.Parameters.Append cmd.CreateParameter("p3", adVarChar, adParamInput, 100, Request.Form("three"))
cmd.Parameters.Append cmd.CreateParameter("p4", adVarChar, adParamInput, 50, Request.Form("four"))
cmd.Parameters.Append cmd.CreateParameter("p5", adVarChar, adParamInput, 50, Request.Form("five"))

cmd.Execute
If Err.Number <> 0 Then Response.Write "DB error: " & Err.Description

conn.Close
Set cmd = Nothing
Set conn = Nothing
%>

Final notes

Do not store plain-text passwords — hash and salt them. If you still see no errors, turn on detailed ASP errors in IIS or use Err.Number/Err.Description while testing to reveal the underlying problem.

Recommended Answers

All 4 Replies

comment following lines
'stud1.open stud2,stud3

'stud2.CursorType = 2
'stud2.lockType = 2

and instead of this
'stud1.open stud2,stud3
write this
stud2.open stud3,stud1

Try this, and I'll let you know where you made mistakes

<%
dim stud1, stud2, stud3
set stud1 = server.createobject("adodb.connection") 
'''You do not open the connection string, you need to set the provider:
'''stud1.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & '''Server.MapPath("amitdatabase.mdb")  
stud1.Provider "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("amitdatabase.mdb") & ";"

'''no need to close and reopen asp brackets.

set stud2 = server.createobject("ADODB.Recordset")
'''You don't have to put the table name infront of the column UNLESS you are using
'''more than 1 table, so keep it simple!
'''stud3 = "SELECT tblComments.Name, tblComments.Comments FROM tblComments;"  
stud3 = "SELECT Name, Comments FROM tblComments"
'''You may or may not need these two lines below, depending on what you play on doing
'''with your database (reading, writing, deleting, paging, etc.)
'''if you have problems after this, try removing the next two lines, or commenting them out.
stud2.CursorType = 2 
stud2.lockType = 2 

'''Now would be the time to open the connection!
stud1.Open
'''You already opened stud1, now you need to open your recordset!
'''stud1.open stud2,stud3
'''You open your recordset with the query (stud3), on the following connection (stud1)
stud2.open stud3, stud1

'''no need to close and reopen asp brackets.

stud2.addnew
stud2("firstname")=request.form("one")
stud2("lastname")=request.form("two")
stud2("email")=request.form("three")
stud2("username")=request.form("four")
stud2("password")=request.form("five")
stud2.update
'''You should add a Requery to this, it redoes the update to ensure no columns were missed.
'''if you have problems, remove requery statement. Sometimes it produces an error.
stud2.requery

'''Don't forget to close the connection, or you will have major problems!
stud1.Close

'''Set them to nothing
stud1 = ""
set stud1 = nothing
stud2 = ""
set stud2 = nothing
%>

No need to write all this
just copy paste following.

<% dim stud1
set stud1=server.createobject("adodb.connection")
stud1.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("amitdatabase.mdb")
%>
<% dim stud2,stud3
set stud2=server.createobject("ADODB.Recordset")
stud3 = "SELECT tblComments.Name, tblComments.Comments FROM tblComments;"
stud2.CursorType = 2
stud2.lockType = 2

'stud1.open stud2,stud3
stud2.open stud3,stud1

%>
<%
stud2.addnew
stud2("firstname")=request.form("one")
stud2("lastname")=request.form("two")
stud2("email")=request.form("three")
stud2("username")=request.form("four")
stud2("password")=request.form("five")
stud2.update
%>

All that it contained was comments, but almost exactly the same code that you have lol. I was just giving him a lesson so he knows what to do in the future.

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.