Ask a Question related to Macromedia Dynamic HTML, Design and Development.
-
bake01 #1
Error Message on Upload
I'M ATTEMPTING TO UPLOAD A .CSV FILE TO MS SQL SERVER USING THIS SCRIPT:
I CAN BROWSE TO MY .CSV FILE BUT WHEN IT TRIED TO LOAD I RECEIVE THIS MESSAGE:
Microsoft VBScript runtime error '800a004c'
Path not found
/casino/scripts/importCSVInc.asp, line 62
IT LOOKED LIKE A PERMISSION ISSUE AT FIRST, BUT I AM ABLE TO BROWSE TO THE
importCSVInc.asp FILE THROUGH MY BROWSER FROM THE SITE ROOT. SO I HAVE TO
THINK IT'S SOMETHING ELSE. ANY IDEAS? THANK YOU!
importCSV.asp
<!--#Include File = "../ASPFramework/Controls/WebControl.asp"-->
<!--#Include File = "../ASPFramework/Controls/Server_Fileuploader.asp" -->
<!--#Include File = "../ASPFramework/Controls/Server_Label.asp" -->
<html>
<head>
<title>Franklin Press - Import CSV File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body id="CLASPbody">
<%Page.Execute%>
<div align="center">
<% Page.OpenForm() %>
<table>
<tr>
<td>
<%cmdFile%>
</td>
</tr>
</table>
<% doResult %>
<% Page.CloseForm() %>
</div>
</body>
</html>
<!--#Include File = "scripts/importCSVInc.asp" -->
AND THE CUSTOM INCLUDE FILE IS:
<!--#Include File = "Database.asp"-->
<%
'VARIABLE DECLARATIONS
Dim cmdFile ' File upload control
Dim lblError ' Label
Dim MyDB ' Database class
Dim nResult
'PAGE EVENT HANDLERS
Public Function Page_Init()
'Page.DebugEnabled = True ' Want to see the trace and session objects and app.
Set cmdFile = New_ServerFileUploader("cmdFile","")
cmdFile.TempUploadPath = Server.MapPath("../Uploads")
Set lblError = New_ServerLabel("lblError")
nResult = 0
End Function
Public Function Page_Controls_Init()
cmdFile.Text = "Upload CSV File"
cmdFile.FileFilter = "csv" 'optional, set to "" to upload any file
cmdFile.MaxUploadSize = 5000000 'optional, set to 0 to upload any size
End Function
Public Function Page_Load()
Page.RegisterWebControlsInClientSide
Set MyDB = New cDatabase
End Function
Public Function Page_PreRender()
End Function
Public Function Page_Terminate()
MyDB.CloseQuery
End Function
'WEBCONTROLS POSTBACK EVENT HANDLERS
Public Function cmdFile_OnUpload()
cmdFile.FileName = "CSVUpload.csv"
cmdFile.SaveFile(Server.MapPath("../Uploads"))
doImportFile(Server.MapPath("../Uploads/" & cmdFile.FileName))
End Function
'SUPPORTING FUNCTIONS
Public Function doImportFile(CSVfile)
Dim fs, f
Dim arrCSVheader
Dim arrCSVline
Dim curTable, curTableField, curTableKey, curTableKeyInd, curCol
Dim arrTableFields(10) ' Contains current table field names; used
' to determine when field names are duplicated.
Dim arrTableKeys(3,5) ' table name, key name, key value
Dim origIndexTable, origIndex, origIndexVal
Dim curIndexTable, curIndex, curIndexVal
Dim query, queryValues
Dim pos, I
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(CSVfile, 1)
' Read the header from the CSV file
arrCSVheader = readCSVline(f)
Do While (f.AtEndOfStream <> True)
' Read a line from the CSV file
arrCSVline = readCSVline(f)
curTable = ""
curTableField = 0
curTableKey = ""
curTableKeyInd = 0
origIndexTable = ""
origIndex = ""
origIndexVal = ""
curIndexTable = ""
curIndex = ""
curIndexVal = ""
curCol = 0
query = ""
queryValues = ""
Do While (curCol < UBound(arrCSVline))
' Handle table definition
If ("TABLE " = Left(arrCSVheader(curCol), 6)) Then
If (("" <> curTable) And ("(" <> Right(query, 1))) Then
query = query & ")" & queryValues & ")"
If (curTable = curIndexTable) Then
doVerifiedQuery query, curIndexTable, curIndex, curIndexVal
Else
doQuery(query)
End If
If ("" <> curTableKey) Then
arrTableKeys(0, curTableKeyInd) = curTable
arrTableKeys(1, curTableKeyInd) = curTableKey
If (curTable = origIndexTable) Then
arrTableKeys(2, curTableKeyInd) = _
getKey(curTable, curTableKey, origIndexTable, origIndex, origIndexVal)
Else
For I = 1 To curTableKeyInd
If (arrTableKeys(0, I - 1) = origIndexTable) Then
arrTableKeys(2, curTableKeyInd) = _
getKey(curTable, curTableKey, origIndexTable, _
arrTableKeys(1, (I - 1)), arrTableKeys(2, (I - 1)))
I = curTableKeyInd
End If
Next
End If
If (curTableKeyInd = UBound(arrTableKeys)) Then
ReDim Preserve arrTableKeys(3, UBound(arrTableKeys) + 5)
End If
curTableKeyInd = curTableKeyInd + 1
End If
End If
curTable = Mid(arrCSVheader(curCol), 7)
curTableField = 0
curTableKey = ""
query = "INSERT INTO " & curTable & " ("
queryValues = " VALUES ("
' End table definition
' Handle index definition
ElseIf (" INDEX" = Right(arrCSVheader(curCol), 6)) Then
curIndexTable = curTable
curIndex = Left(arrCSVheader(curCol), Len(arrCSVheader(curCol)) - 6)
curIndexVal = arrCSVline(curCol)
If ("" = origIndexTable) Then
origIndexTable = curIndexTable
origIndex = curIndex
origIndexVal = curIndexVal
End If
' Add the value to the query
If ("(" <> Right(query, 1)) Then
query = query & ", "
queryValues = queryValues & ", "
End If
query = query & curIndex
' Quote the field value
' TODO: handle embedded single quotes
queryValues = queryValues & "'" & curIndexVal & "'"
arrTableFields(curTableField) = curIndex
If (UBound(arrTableFields) = curTableField) Then
ReDim Preserve arrTableFields(UBound(arrTableFields) + 10)
End If
curTableField = curTableField + 1
' End index definition
' Handle primary key definition
ElseIf (" KEY" = Right(arrCSVheader(curCol), 4)) Then
curTableKey = Left(arrCSVheader(curCol), Len(arrCSVheader(curCol)) - 4)
' End primary key definition
Else
' Handle key reference
pos = InStr(arrCSVheader(curCol), " REF ")
If (0 <> pos) Then
For I = 1 To curTableKeyInd
If (Mid(arrCSVheader(curCol), pos + 5) = arrTableKeys(0, I - 1)) Then
If ("(" <> Right(query, 1)) Then
query = query & ", "
queryValues = queryValues & ", "
End If
query = query & Left(arrCSVheader(curCol), pos - 1)
queryValues = queryValues & CStr(arrTableKeys(2, I - 1))
End If
Next
' End key reference
' Handle field value
Else
' Duplicate field?
For I=1 To curTableField
If ((arrCSVheader(curCol) = arrTableFields(I - 1)) And _
(InStr(query, arrCSVheader(curCol)))) Then
If (("" <> curTable) And ("(" <> Right(query,1))) Then
query = query & ")" & queryValues & ")"
If (curTable = curIndexTable) Then
doVerifiedQuery query, curIndexTable, curIndex, curIndexVal
Else
doQuery(query)
End If
' Don't store another key for this table;
' we don't support indexing tables by multiple keys.
End If
' Search the query string for the duplicate field
pos = InStr(query, arrCSVheader(curCol))
' Preserve all of the prior fields
query = RTrim(Left(query, pos - 1))
If ("," = Right(query, 1)) Then
query = RTrim(Left(query, Len(query) - 1))
End If
curTableField = countFields(query)
queryValues = trimQuery(queryValues, curTableField)
End If
Next
' Not a duplicate field
If ("(" <> Right(query, 1)) Then
query = query & ", "
queryValues = queryValues & ", "
End If
query = query & arrCSVheader(curCol)
' Quote the field value
' TODO: handle embedded single quotes
If ("String" = TypeName(arrCSVline(curCol))) Then
queryValues = queryValues & "'" & arrCSVline(curCol) & "'"
Else
queryValues = queryValues & CStr(arrCSVline(curCol))
End If
arrTableFields(curTableField) = arrCSVheader(curCol)
If (curTableField = UBound(arrTableFields)) Then
ReDim Preserve arrTableFields(UBound(arrTableFields) + 10)
End If
curTableField = curTableField + 1
End If
End If
' Move to the next column in the CSV line
curCol = curCol + 1
Loop
' Do the last query
If ("(" <> Right(query, 1)) Then
query = query & ")" & queryValues & ")"
If (curTable = curIndexTable) Then
doVerifiedQuery query, curIndexTable, curIndex, curIndexVal
Else
doQuery(query)
End If
End If
Loop
' TODO: Redirect to success page?
nResult = 1
f.Close
Set f=Nothing
Set fs=Nothing
End Function
Public Function readCSVline(f)
Dim textLine
Dim arr()
Dim colNum, prevPos
Dim quoteFlag
Dim I
textLine = f.ReadLine
colNum = 0
prevPos = 0
quoteFlag = False
ReDim arr(30)
For I=1 To Len(textLine)
If (Chr(34) <> Mid(textLine, I, 1)) Then
If (("," = Mid(textLine, I, 1)) And (Not quoteFlag)) Then
arr(colNum) = Trim(Mid(textLine, prevPos + 1, (I - prevPos) - 1))
prevPos = I
' If the field is quoted, remove the quotes
If ((Chr(34) = Left(arr(colNum), 1)) And (Chr(34) = Right(arr(colNum),
1))) Then
arr(colNum) = Mid(arr(colNum), 2, Len(arr(colNum))-2)
End If
colNum = colNum + 1
End If
Else
quoteFlag = Not(quoteFlag)
End If
If (colNum = UBound(arr)) Then
ReDim Preserve arr(UBound(arr) + 30)
End If
Next
' Grab the last field
If ("," <> Right(textLine,1)) Then
arr(colNum) = Mid(textLine, prevPos + 1, Len(textLine) - prevPos)
' If the field is quoted, remove the quotes
If ((Chr(34) = Left(arr(colNum), 1)) And (Chr(34) = Right(arr(colNum), 1)))
Then
arr(colNum) = Mid(arr(colNum), 2, Len(arr(colNum))-2)
End If
colNum = colNum + 1
Else
arr(colNum) = ""
colNum = colNum + 1
End If
R
bake01 Guest
-
How To Supress Acrobat Error Message And Alert Message
Is there any way to supress those pop up message? If can't, is there any way to catch it? -
Upload Error Message
On large file uploads (greater than 50 MB) I receive the following message Error reading remainder of content stream (total bytes = 74903302,... -
Error Message When Sending Message In Windows Mail
Am I the only one getting an error message when replying to a posted message using Windows Mail. Every time I send a message I get a popup error... -
Error Message "A drawing error ocurrred which is probably due to an out-of-memory condition. Try qu
I am running Acrobat Reader 5.0 on a Mac Powerbook running OS 9.2 and keep getting "A drawing error occurred which is probably due to an out of... -
CFFile Problem in MX7 - No Error Message, No Upload
We have a CFFile tag writing to a UNC Path. Its been working for years, and suddenly its acting terribly -- it does not return an error message, and...



Reply With Quote

