Forum Moderators: open
Sub retrieveDataFromFile()
'move the uploaded data from the .csv file to an array
set rst = server.CreateObject("ADODB.Recordset")
Set cnn = server.CreateObject("ADODB.Connection")
cnn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\upload;Extended Properties=Text;"
cnn.Open
strSQL = "Select * from " & strFileName
rst.Open strSQL, cnn
sArray = rst.getRows()
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
'call the method to save the data to a temp table in SQL server
saveDatatoDatabase()
End Sub
How can I have this asp page continue to read the csv file that is uploaded into the array?
I am knew to asp however a quick study. Any help would be greatly appreciated. I do have MS SQL 2005 Standard x64 installed on this machine. The line "saveDatatoDatabase()" saves the array into an SQL DB just fine, as this very code works on our aging x86 web server.
Depending on your version of IIS you can set the application pool to run 32 bit applications.
In IIS 7.x it goes as follows:
- Find the Application Pool for your Website/Web Application (under Server -> Application Pools)
- Right-Click and select Advanced Settings...
- Set Enable 32-Bit Applications to True.
This works fine for my 'older' websites which use JET 4.0 and MS Access databases. (not sure if it also works for opening .csv files, although I think it will.)
I don't have an install of Windows 2003 64 bit at the moment so I haven't been able to test this in IIS 6, maybe someone else has more info on this.
We are planning on having a second, identical, server setup with load balancing for IIS (because we perform time card collection via web portal), as well as SQL replication between both servers and back to our corporate office where the payroll processing occurs. These server will be sitting in a data center connected to our corporate office via a point to point T connection (I know, slow, but all that is currently available where our office is).
Sorry, I sent you on the wrong track with the Microsoft Text Driver, apparently this also no longer works in a 64 bit environment.
[learn.iis.net...]
Acccess Error '80004005' [support.microsoft.com]
Other Items of Reference:
There is a tool I have used a few times released by Microsoft call Logparser 2.2 [microsoft.com]. It does provide a COM interface so it should be able to be used via ASP Classic but it is still 32 bit from what I can read, with no 64 bit version available as of writing this.
All of the MS articles I have read so far say you can only run one or the other, not both
You mention the 'Jet based tool we have', is this a separate tool? Is rewriting it in ASP.Net an option?
Also, here is an older thread on Reading a CSV file into an Array with ASP [webmasterworld.com], this method uses a filestream instead of JET 4, may also be an option.
You will see that it uses Jet 4.0 and a connection to our SQL 2005 DB
<%@Language=VBScript%>
<%
Option Explicit
Response.Expires = 0
Response.Buffer = True
Server.ScriptTimeout = 180
%>
<!--#include virtual="/tools/folderlist.asp"-->
<%
'********************************************************************
' Script-Level (Global) Variables
'********************************************************************
Dim strTest, s_vArray, s_i, s_objAcumen, s_rightboxHeader, s_pageHeader, strUploadError, iRow, booleanValidateData
Dim s_strBROKERAGE, s_strDB, s_struserid, objAcumenUserSettings, s_action, s_strConfirmation, s_strErrors, strLogText
Dim objUpload, strFileSavePath, strGUID, strFileName, strExt, s_file_name, s_newsletter, deleteDate, deleteCheck, iCol
dim strStatus, fso, theFile, strLogFileName, sClientFirst, sClientLast
Dim cnn, rst, strSQL, sArray, y, x, newArray, isFound, aRow, thisClient, OldChar, Char, i, TempString
dim sEmployeeName, sDateOfBirth, sClientName, sClientNumber, sMedicareNumber, sBatchNumber, sHours, sUnitBilling, sBilling
dimsUnits, sUnitRate, sPeriodStart, sPeriodEnd, sPayRate, sServiceDate, sCheckNumber, sCheckDate, sServiceCode, sTaxes
'********************************************************************
' Page Execution
'********************************************************************
Call Initialize()
Call Main()
Sub Initialize()
On Error Resume Next
'what folder to save the files uploaded in
strFileSavePath = "D:\upload\"
'initialize the upload com+ component
Set objUpload = Server.CreateObject("Dundas.Upload.2")
objUpload.SaveToMemory
'get the action parameter from the submitted HTML form
s_action = objUpload.Form("action")
If Err.Number <> 0 Then
s_strErrors = s_strErrors & "Initialize - " & Err.Number & Err.Description & Err.Source & "^"
End If
End Sub
Sub Main()
Select Case s_action
Case "Save"
Call uploadFile()
response.Redirect("summarize.asp")
End Select
Call DisplayInterface()
End Sub
Sub DisplayInterface()
%>
<html>
<head>
<title>Web Tool</title>
</head>
<body>
<form name="uploadFile" method="post" enctype="multipart/form-data">
<table width="100%">
<tr>
<td width="100%">
<b>Web Toolkit</b>
<a href="index.asp">Main Menu</a>
<a href="javascript:window.print();">Print</a>
<hr/>
</td>
</tr>
<tr>
<td>
<strong>Billing Summary Upload</strong></font>
</td>
</tr>
</table>
<table>
<tr>
<td>
Browse to the .csv file to be uploaded:
</td>
</tr>
<tr>
<td>
<input name="path_name" type="file" class="button" value="" size="50">
</td>
</tr>
<tr>
<td>
<input type="hidden" name="action" id="action">
<input class="button" type="button" name="Save" value="Upload" onClick="savePage()">
</td>
</tr>
<tr>
<td>
<font color="red"><%response.Write(strStatus)%></font>
</td>
</tr>
</table>
</form>
</body>
</html>
<%
End Sub
Sub uploadFile()
'fix up the file name for allowed characters
strFileName = request.Cookies("acu")("userid") & "_" & date() & "_" & time() & ".csv"
strFileName = replace(strFileName, ":", "_")
strFileName = replace(strFileName, "/", "_")
strFileName = replace(strFileName, " ", "_")
'create schema.ini for the new filename
Set fso=CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(strFileSavePath & "schema.ini", 2, True)
theFile.WriteLine "[" & strFileName & "]"
theFile.WriteLine "Format=CSVDelimited"
theFile.WriteLine "CharacterSet=ANSI"
theFile.WriteLine "Col1=a Text Width 100"
theFile.WriteLine "Col2=b Text Width 100"
theFile.WriteLine "Col3=c Text Width 100"
theFile.WriteLine "Col4=d Text Width 100"
theFile.WriteLine "Col5=e Text Width 100"
theFile.WriteLine "Col6=f Text Width 100"
theFile.WriteLine "Col7=g Text Width 100"
theFile.WriteLine "Col8=h Text Width 100"
theFile.WriteLine "Col9=i Text Width 100"
theFile.WriteLine "Col10=j Text Width 100"
theFile.WriteLine "Col11=k Text Width 100"
theFile.WriteLine "Col12=l Text Width 100"
theFile.WriteLine "Col13=m Text Width 100"
theFile.WriteLine "Col14=n Text Width 100"
theFile.WriteLine "Col15=o Text Width 100"
theFile.WriteLine "Col16=p Text Width 100"
theFile.WriteLine "Col17=q Text Width 100"
theFile.WriteLine "Col18=r Text Width 100"
theFile.WriteLine "Col19=s Text Width 100"
theFile.Close
Set fso = Nothing
Set theFile = Nothing
'upload the file using the com+ upload component
If objUpload.Files.Count <> 0 Then
objUpload.Files(0).SaveAs (strFileSavePath & strFileName)
Else
strFileName =""
strExt =""
End If
strStatus = "File uploaded successfully at " & time() & " on " & date()
'release objUpload from memory
Set objUpload = Nothing
'call the retrieveDataFromFile() method to get the uploaded file's data into memory
retrieveDataFromFile()
End Sub
Sub retrieveDataFromFile()
'move the uploaded data from the .csv file to an array
set rst = server.CreateObject("ADODB.Recordset")
Set cnn = server.CreateObject("ADODB.Connection")
cnn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\upload;Extended Properties=Text;"
cnn.Open
strSQL = "Select * from " & strFileName
rst.Open strSQL, cnn
sArray = rst.getRows()
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
'call the method to save the data to a temp table in SQL server
saveDatatoDatabase()
End Sub
Sub saveDatatoDatabase()
'set up sql server connections
set rst = server.CreateObject("ADODB.Recordset")
Set cnn = server.CreateObject("ADODB.Connection")
cnn.ConnectionString = "Provider=SQLOLEDB;server=xyz;database=xyz;User ID=xyz;Password=xyz"
cnn.Open
'delete anything in the temp table
strSQL = "delete from BillingTemp"
rst.Open strSQL, cnn
'cycle through and validate the array of uploaded data.
For iRow = 0 To UBound(sArray,2)
'check each column in this row for nulls before saving fields to variables
For iCol = 0 to UBound(sArray,1)
'if any of the fields are null, set them to empty string so it doesn't crash
if isnull(sArray(iCol,iRow)) then
sArray(iCol,iRow) = ""
end if
Next
'save each field in this row of the array to a variable
sEmployeeName = sArray(0,iRow)
sDateOfBirth = sArray(1,iRow)
sClientName = sArray(2,iRow)
sClientNumber = sArray(3,iRow)
sMedicareNumber = sArray(4,iRow)
sBatchNumber = sArray(5,iRow)
sHours = sArray(6,iRow)
sUnitBilling = sArray(7,iRow)
sUnits = sArray(8,iRow)
sUnitRate = sArray(9,iRow)
sPeriodStart = sArray(10,iRow)
sPeriodEnd = sArray(11,iRow)
sPayRate = sArray(12,iRow)
sServiceDate = sArray(13,iRow)
sCheckNumber = sArray(14,iRow)
sCheckDate = sArray(15,iRow)
sServiceCode = sArray(16,iRow)
sTaxes = sArray(17,iRow)
sBilling = sArray(18,iRow)
'check this row of uploaded data for validation errors
checkRowForErrors()
'split the client name into first and last names
sClientLast = Left(sClientName, InStr(sClientName, ",") - 1)
sClientFirst = Right(sClientName, Len(sClientName) - InStr(sClientName, ",") - 1)
'if true then data validated successfully - insert the array row's data into the temp table
strSQL = "insert into BillingTemp values('" & sClientLast & "','" & sClientFirst & "','" & sMedicareNumber & "','" & sPeriodStart & "','" & sPeriodEnd & "','" & sServiceDate & "','" & sBilling & "','" & sServiceCode & "')"
'response.write(strSQL)
'response.end()
rst.Open strSQL, cnn
'move to the next row down
Next
'close and release connection and recordset
Set rst = Nothing
Set cnn = Nothing
End Sub
Function checkRowForErrors()
'validate the data and check for errors here
End Function
%>
<script language="JavaScript">
function savePage()
{
if(document.uploadFile.path_name.value == "")
{
alert("You must select a .csv file to upload");
}
else
{
document.uploadFile.action.value = "Save";
document.uploadFile.submit();
}
}
</script>