Solved

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

Posted on 2004-08-07
14
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

 
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
 
LVL 23

Expert Comment

by:Saqib Khan
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remove LF from html text 5 420
submit button form code 2 439
Does Adobe/Dreamweaver Have Free Website Templates? 2 432
Need icon art 9 145
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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