Adding fields to a database??? Help Please - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Adding fields to a database??? Help Please

Hello, i am trying to add a name, username and password to a database and i get this error when running it.

Database or object is read-only.
/registerresult.asp, line 46

This is the code: (the bit that doesn't seem to work is the else bit(i think?))
[code]
<%Language=VBScript%>



<%
Response.Buffer = True 'allows for redirects

dim conn, rs, strName, strUsername, strPassword

'get details from asp form
strName = request.form("name")
strUsername = request.form("username")
strPassword = request.form("pwd1")

'create connection
set conn = Server.CreateObject("ADODB.Connection")

'open connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.Mappath("./library.mdb") & _
"; Jet OLEDB:Database Password="

'create recordset
set rs = Server.CreateObject("ADODB.Recordset")

'open and populate recordset using sql query
rs.Open "SELECT * FROM Members " & _
"WHERE username='" & strUsername & "'", _
conn, adOpenStatic, adLockReadOnly, adCmdText

if not rs.EOF then

Session("hasError") = true
Session("justRegistered") = false
Session("usernameEntered") = strUsername
Session("nameEntered") = strName
Response.Redirect("./register.asp")

else

Session("hasError") = false
Session("justRegistered") = true

rs.Close
rs.Open "Members", conn, adOpenStatic, adLockOptimistic, adCmdTable
rs.AddNew
rs.Fields("Name").value = strName
rs.Fields("Username").value = strUsername
rs.Fields("Password").value = strPassword
rs.Update
Response.Redirect("./register.asp")
end if

rs.Close
conn.Close

set rs=nothing
set conn=nothing
%>[/code]

Thanks for any help!

Comments

  • FlakesFlakes Posts: 642Member
    : Hello, i am trying to add a name, username and password to a database and i get this error when running it.
    :
    : Database or object is read-only.
    : /registerresult.asp, line 46
    :
    : This is the code: (the bit that doesn't seem to work is the else bit(i think?))
    : [code]
    : <%Language=VBScript%>
    :
    :
    :
    : <%
    : Response.Buffer = True 'allows for redirects
    :
    : dim conn, rs, strName, strUsername, strPassword
    :
    : 'get details from asp form
    : strName = request.form("name")
    : strUsername = request.form("username")
    : strPassword = request.form("pwd1")
    :
    : 'create connection
    : set conn = Server.CreateObject("ADODB.Connection")
    :
    : 'open connection
    : conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
    : Server.Mappath("./library.mdb") & _
    : "; Jet OLEDB:Database Password="
    :
    : 'create recordset
    : set rs = Server.CreateObject("ADODB.Recordset")
    :
    : 'open and populate recordset using sql query
    : rs.Open "SELECT * FROM Members " & _
    : "WHERE username='" & strUsername & "'", _
    : conn, adOpenStatic, adLockReadOnly, adCmdText
    :
    : if not rs.EOF then
    :
    : Session("hasError") = true
    : Session("justRegistered") = false
    : Session("usernameEntered") = strUsername
    : Session("nameEntered") = strName
    : Response.Redirect("./register.asp")
    :
    : else
    :
    : Session("hasError") = false
    : Session("justRegistered") = true
    :
    : rs.Close
    : rs.Open "Members", conn, adOpenStatic, adLockOptimistic, adCmdTable
    : rs.AddNew
    : rs.Fields("Name").value = strName
    : rs.Fields("Username").value = strUsername
    : rs.Fields("Password").value = strPassword
    : rs.Update
    : Response.Redirect("./register.asp")
    : end if
    :
    : rs.Close
    : conn.Close
    :
    : set rs=nothing
    : set conn=nothing
    : %>[/code]
    :
    : Thanks for any help!
    :
    This error usually indicates that you did not set the appropriate permissions on the database, "library.mdb". The security account used by the web server IIS service should have at least "Write" permissions on the database file

    To adjust the file permissions, you need to locate the file "library.mdb" by using "My computer". Right click on the file, click on "Properties". Next, click on "Security". There are several user/system accounts listed, you'll need to modify the permissions for the account that the IIS web service uses (Usually IUSER_youservername .if you don't know, you can always add the user "Everyone" and give it "Full Control").

    If your hard drive is formatted NTFS, you can set permissions on files and folders by right-clicking on the file. If your XP workstation is a standalone or part of a workgroup, the security tab may be hidden. To unhide, open Windows Explorer. Choose Folder Options from the Tools menu. On the View tab, scroll to the bottom of the Advanced Settings. Clear the check box next to "Use Simple File Sharing." Click OK to apply the change.
Sign In or Register to comment.