Solved

Check new username combined with Insert record behavior not working in ASP...  Stuck!

Posted on 2004-08-07
14
230 Views
Last Modified: 2010-04-25
Can't get this!  I have a form for users to create login info that inserts in to Access database.  This works fine on its own.  When I try to add DWMX's check new username behavior, I get an error—just when a unique username is entered.  If I try a username that already exists in the DB, it redirects just fine.  

The error is:

Microsoft JET Database Engine error '80004005'

Could not use ''; file already in use.

/bonedisease/login/create.asp, line 142


I think it is a opening/closing connection thing, but I don't know enough to see what I need to do.  The code is below, and I've noted line 142...

Getting urgent..

--

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/connBone.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Redirect if username exists
MM_flag="MM_insert"
If (CStr(Request(MM_flag)) <> "") Then
  MM_dupKeyRedirect="emailexists.asp"
  MM_rsKeyConnection=MM_connBone_STRING
  MM_dupKeyUsernameValue = CStr(Request.Form("Email"))
  MM_dupKeySQL="SELECT Email FROM tblLogin WHERE Email='" & MM_dupKeyUsernameValue & "'"
  MM_adodbRecordset="ADODB.Recordset"
  set MM_rsKey=Server.CreateObject(MM_adodbRecordset)
  MM_rsKey.ActiveConnection=MM_rsKeyConnection
  MM_rsKey.Source=MM_dupKeySQL
  MM_rsKey.CursorType=0
  MM_rsKey.CursorLocation=2
  MM_rsKey.LockType=3
  MM_rsKey.Open
  If Not MM_rsKey.EOF Or Not MM_rsKey.BOF Then
    ' the username was found - can not add the requested username
    MM_qsChar = "?"
    If (InStr(1,MM_dupKeyRedirect,"?") >= 1) Then MM_qsChar = "&"
    MM_dupKeyRedirect = MM_dupKeyRedirect & MM_qsChar & "requsername=" & MM_dupKeyUsernameValue
    Response.Redirect(MM_dupKeyRedirect)
  End If
  MM_rsKey.Close
End If
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "Create") Then

  MM_editConnection = MM_connBone_STRING
  MM_editTable = "tblLogin"
  MM_editRedirectUrl = "welcome.asp"
  MM_fieldsStr  = "FirstName|value|LastName|value|Email|value|LogPassword|value"
  MM_columnsStr = "FirstName|',none,''|LastName|',none,''|Email|',none,''|LogPassword|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
 
  ' set the form values
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>

<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

Session("MM_Username") = Request("Email")

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_formVal = MM_fields(MM_i+1)
    MM_typeArray = Split(MM_columns(MM_i+1),",")
    MM_delim = MM_typeArray(0)
    If (MM_delim = "none") Then MM_delim = ""
    MM_altVal = MM_typeArray(1)
    If (MM_altVal = "none") Then MM_altVal = ""
    MM_emptyVal = MM_typeArray(2)
    If (MM_emptyVal = "none") Then MM_emptyVal = ""
    If (MM_formVal = "") Then
      MM_formVal = MM_emptyVal
    Else
      If (MM_altVal <> "") Then
        MM_formVal = MM_altVal
      ElseIf (MM_delim = "'") Then  ' escape quotes
        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
      Else
        MM_formVal = MM_delim + MM_formVal + MM_delim
      End If
    End If
    If (MM_i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End If
    MM_tableValues = MM_tableValues & MM_columns(MM_i)
    MM_dbValues = MM_dbValues & MM_formVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection <!--this is line 142, indicated in the error msg -->
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
0
Comment
Question by:bfider2004
  • 7
  • 3
  • 3
  • +1
14 Comments
 
LVL 8

Expert Comment

by:CoolATIGuy
ID: 11745187
0
 

Author Comment

by:bfider2004
ID: 11745259
Yeah, all the research I've done on the error has pointed to problems with permissions.  I'm pretty certain this is not a permissions issue.  The record insertion works fine when I don't put that "Check New Username" behavior in.   When I do add the "Check New Username" behavior, I get the error—but only when the username is NOT unique.  The error points to the insert record code after the "Check New Username" code.  (which comes at:

MM_editCmd.ActiveConnection = MM_editConnection

)

I'm bound and determined to figure this out.  Thanks for your help/
0
 
LVL 8

Expert Comment

by:alexhogan
ID: 11745275
You are getting this error because the connection to the db is already open.

If you check the directory where the db is you will find a file named the same as the db but with a .ldb extension.  This is what is causing your problem.

At the end of your page be sure you are closing the connection to the db and this error will go away...
0
 
LVL 8

Expert Comment

by:CoolATIGuy
ID: 11745278
Well, in this part:

 If Not MM_rsKey.EOF Or Not MM_rsKey.BOF Then
    ' the username was found - can not add the requested username


What is MM_rsKey.EOF and MM)rsKey.BOF?  I don't see them getting set...

CoolATIGuy
0
 
LVL 8

Expert Comment

by:CoolATIGuy
ID: 11745303
This page has info on databasing in ASP, including closing connections: http://www.tnsites.com/support/s_databaseconn.asp

CoolATIGuy
0
 

Author Comment

by:bfider2004
ID: 11745318
alexhogan - Like this?  I can't tell if DW is opening a connection and not closing it, unbeknownst to me...  at this point, I don't know a db connection from a pigskin.  

</hml>
<%
MM_editConnection .Close()
Set MM_editConnection = Nothing
%>
0
 

Author Comment

by:bfider2004
ID: 11745335
CoolATIGuy -

If Not MM_rsKey.EOF Or Not MM_rsKey.BOF Then
    ' the username was found - can not add the requested username

This is the DW added code for the "Check New Username" behavior...  I've not had this prob with any similar DW code.  Not saying it's not possible...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 23

Expert Comment

by:adilkhan
ID: 11745620
Make Sure All connections are Close to Database.

in your Asp Page on the Bottom Always Close the Connection like this..

Conn.Close
Set Conn = Nothing

And See if a Instance of MS Access is Already open.

if nothing helps, Restart your Computer.
0
 

Author Comment

by:bfider2004
ID: 11746303
I'll try this:

Conn.Close
Set Conn = Nothing

All this is happening on a remote server, so it's not that I have the database open, or anything.  It must be an unclosed connection.  If my connection is called connBone would I put:

connBone.Close
Set connBone = Nothing

0
 
LVL 8

Expert Comment

by:alexhogan
ID: 11749668
[snip]
connBone.Close
Set connBone = Nothing
[/snip]

Correct...

What you are doing is setting the objects method to close and then distroying the instance.
0
 

Author Comment

by:bfider2004
ID: 11749759
I put this at the end of the page:

<%
connBone.Close
Set connBone = Nothing
%>

and not only is it not working, but I'm getting error message at the bottom of the page:

Microsoft VBScript runtime error '800a01a8'

Object required: ''

/bonedisease/login/create.asp, line 253 <!-- the end of the page where the close is -->

--

Since I can't find any documentation on problems similar to this one, it is obviously only happening to me.  

The form inserts into the database just fine on its own.  But when I combine this with the check new username, i get the errors.  I've never had DW open a connection and not close it by itself.  This is pissing me off...

0
 

Author Comment

by:bfider2004
ID: 11749777
This appears to be where the Check New Username code is, and this appears to close it, correct?:

MM_rsKey.Close

Then in the Insert record code, I see this line:

MM_editCmd.ActiveConnection.Close

Very confused, perhaps I'm in over my head...
0
 
LVL 8

Accepted Solution

by:
alexhogan earned 250 total points
ID: 11755653
Your connection is;

MM_rsKeyConnection at the top of your page where it is assigned the value from the string MM_connBone_STRING.

MM_rsKeyConnection = MM_connBone_STRING

MM_rsKey is the instance of the object that is created to do your update or insert or even read.  By setting MM_rsKey.Close and then MM_rsKey = Nothing, are destroying the instance of that object.  Your connection should be closed at the same time.

The only thing that I don't see is where MM_editConnection is being closed.

Since however you are getting a line error on 142, try commenting out that line number.  It is opeining a new connection to the database.
0
 

Author Comment

by:bfider2004
ID: 11759807
while my code was reading:

MM_rsKey.Close

this apparantly was not enough.  i added Set MM_rsKey = Nothing after it, and it worked.  halelluia, it works....

thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Footer only sticks to bottom of browser with absolute positioning 13 320
Printing source code 2 306
DW UserID Session from Login 1 109
Font: I need Lato on my Mac 10 177
For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now