Forums

This topic is locked

Database Insert

Posted 27 Mar 2001 23:30:05
1
has voted
27 Mar 2001 23:30:05 Gary Costigan posted:
I am trying to make a page that will enter data into a database.

I have a connection made to the database from both my production machine
and the web server. When I test the link it comes back as "Connection test OK".

When I make the insert record entry I find the database to connect to, the
table is there, and the fields are there.

When I go to the page and hit the Submit button I keep getting the following response:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine
cannot open the file '(unknown)'. It is already opened exclusively by another
user, or you need permission to view its data.

/performance/Gary Hold/DatasurveyTest03.asp, line 27



I have tried everything and can't seem to make it work.

I am using UD4 and the datbase is an Access database.

Here is the code:

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

MM_editAction = CStr(Request("URL")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & 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="DataSurveySorry.html"
MM_rsKeyConnection=MM_DataInsert02_STRING
MM_dupKeyUsernameValue = CStr(Request.Form("txtUsername")
MM_dupKeySQL="SELECT Username FROM Employees WHERE Username='" & 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") <> "" Then

MM_editConnection = MM_DataInsert02_STRING
MM_editTable = "Employees"
MM_editRedirectUrl = "DataSurveyWelcome.asp"
MM_fieldsStr = "txtUsername|value|txtPassword|value|txtConfirm|value"
MM_columnsStr = "Username|',none,''|Password|',none,''|Confirm|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|"
MM_columns = Split(MM_columnsStr, "|"

' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(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

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

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),","
Delim = MM_typeArray(0)
If (Delim = "none" Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none" Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none" Then EmptyVal = ""
If (FormVal = "" Then
FormVal = EmptyVal
Else
If (AltVal <> "" Then
FormVal = AltVal
ElseIf (Delim = "'" Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''" & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & 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
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
%>
<html>
<head>
<title>New User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1><font face="Arial, Helvetica, sans-serif">Register a new
user:</font></h1>
<form name="form1" method="POST" action="<%=MM_editAction%>">
<table width="100%" border="0">
<tr>
<td>
<div align="center">Enter a Username:</div>
</td>
<td>
<div align="left">
<input type="text" name="txtUsername">
</div>
</td>
</tr>
<tr>
<td>
<div align="center">Enter a Password:</div>
</td>
<td>
<div align="left">
<input type="text" name="txtPassword">
</div>
</td>
</tr>
<tr>
<td>
<div align="center">Confirm Password</div>
</td>
<td>
<div align="left">
<input type="text" name="txtConfirm">
</div>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="true">
</form>
<h1> </h1>
</body>
</html>

Anyone have the same problem?

Thanks

Gary Costigan
Dallas, Tx.



Replies

Replied 03 Apr 2001 22:39:51
03 Apr 2001 22:39:51 George Petrov replied:
Hi Gary,

You might want to read more about Access ADo Connections.
There is a very good tutorial about this:

www.basic-ultradev.com/articles/ADOConnections/

Greetings,
George Petrov
www.UDzone.com
Replied 04 Apr 2001 14:49:15
04 Apr 2001 14:49:15 Gary Costigan replied:
Hi George,

Thanks for the reply. I did some digging myself last week and found out that windows NT 4.0 and Access have a Read/Write etc bug and locked out the database. I gave up and built my table in SQL7.0 and everything works fine!!!

Thanks again.

Gary

You might want to read more about Access ADo Connections.
There is a very good tutorial about this:

www.basic-ultradev.com/articles/ADOConnections/

Greetings,
George Petrov
www.UDzone.com


Reply to this topic