问题
We have an old ASP Classic website which has been running on Windows 2003 and needs to be moved to 2012.
Most of the site works apart from a section where we need to be able to upload CSV or Excel documents full of categories to the server.
I know no Microsoft Driver existed at the time of Windows 2008 which is why we have had to leave the site on 2003 for so long but we are trying to solve this issue now either by -finding the correct MS Text/CSV/XLS driver for Windows 2012 -buying a component to do the job for us
After searching I found this MS KB article > http://www.microsoft.com/en-us/download/details.aspx?id=13255
Which says it should do the job however when I upload Excel with the following code which I have got from the KB article
Set objConnectionCSV = Server.CreateObject("ADODB.Connection")
Set objCSVRecs = Server.CreateObject("ADODB.Recordset")
'* Get path and extension of uploaded file - earlier on using ASPUpload
strPath = objFile.Path
strExt = lcase(Right(strPath,Len(strPath)-InStrRev(strPath,".")))
'* try with new driver code
With objConnectionCSV
.Provider = "Microsoft.ACE.OLEDB.12.0"
'* it errors on this line!
.Open "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & strPath & ";"""
'* old code which I don't get to which required data to be on sheet 1
On Error Resume Next
Set objCSVRecs = .Execute("[Sheet1$]")
If Err.number <> 0 Then
strErrMessage = "Error opening file: " & Err.number & " " & Err.Description & ";"
Err.Clear
End If
End With
I get this error on the line
.Open "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & strPath & ";"""
Microsoft Access Database Engine error '80004005'
Could not find installable ISAM.
Is this the right text driver?
Does something else need to be done e.g IIS settings or different code?
We have restarted IIS and played around with permissions and it's running in 64 bit mode.
Does anyone have a solution to this problem or know of a workaround e.g a component I could use/buy as I don't want to have to start writing a file parser in ASP classic myself at this point in time.
Even if I can only handle CSV files and not XLS,XLSX etc then that would be good enough but I just need to know the code to use, the correct connection string and anything to install or set in IIS.
Thanks for your help in advance.
回答1:
It looks like OLEDB and ODBC are being used at the same time.
OLEDB
.Provider = "Microsoft.ACE.OLEDB.12.0"
ODBC
.Open "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & strPath & ";"""
Since these data source APIs are entirely different and accomplish the same task. Here is a StackOverflow's answer which discusses the differences.
Remove or comment out this line.
.Provider = "Microsoft.ACE.OLEDB.12.0"
Update
Replace
Set objCSVRecs = .Execute("[Sheet1$]")
with this
Set objCSVRecs = .Execute("SELECT * FROM [Sheet1$]")
The code below was setup on a Windows 2012 R2 VM.
Given: An Excel spreadsheet with the fields id, LastName, FirstName was created for this demo.
<%
Set objConnectionCSV = Server.CreateObject("ADODB.Connection")
Set objCSVRecs = Server.CreateObject("ADODB.Recordset")
'Important: Be sure your strPath variable contains a value. For testing purposes, I hard coded a value.
strPath = objFile.Path
strExt = ".xlsx"
'Opening tags for asp page
response.write "<html><body>"
With objConnectionCSV
.Open "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & strPath & ";"""
On Error Resume Next
Set objCSVRecs = .Execute("select * from [Sheet1$]")
Do While Not objCSVRecs.EOF
response.write "Data row: " & objCSVRecs("id").Value & " Name = " & objCSVRecs("LastName").Value & ", " & objCSVRecs("FirstName").Value & "<br/>"
objCSVRecs.MoveNext
Loop
If Err.number <> 0 Then
strErrMessage = "Error opening file: " & Err.number & " " & Err.Description & ";"
Err.Clear
End If
End With
'End tags for asp page
response.write "</body></html>"
%>
The Results
来源:https://stackoverflow.com/questions/28303691/asp-classic-text-driver-for-windows-2012