S
simon
This is a strange one. In ASP.Net v1.1 using VB, I'm using an
ODBCDataReader to read from a CSV file.
Most of the time it works, but if the "description" field contains more
than 2046 chars, I get a NO_DATA error (see below for full error) when
trying to read that row. If this field contains 2046 chars or less,
then everything works fine.
There are about 6800 rows or lines in the CSV file. However, if I
reduce the amount of lines in the CSV to, say 25, then the description
field can contain more than 2046 chars without causing the error.
Here's a sample from my code:
'Save uploaded file to disk.
filCSV.PostedFile.SaveAs(server.MapPath("import/properties.csv"))
'Import data from CSV into MSSQL.
dim strTxtConString as string = "Driver={Microsoft Text Driver (*.txt;
*.csv)};Dbq=" & Server.MapPath("import/") & ";"
dim conTxt as ODBCConnection = New ODBCConnection(strTxtConString)
dim cmdTxt as ODBCCommand
dim drTxt as ODBCDataReader
conTxt.Open()
cmdTxt = conTxt.CreateCommand()
cmdTxt.CommandText = "SELECT * FROM [properties.csv]"
cmdTxt.CommandType = CommandType.Text
drTxt = cmdTxt.ExecuteReader()
Do While drTxt.Read()
try
response.write("<br>" & drTxt("Number of characters").ToString() & "
" & drTxt("Description").ToString())
catch
response.write("<br>Error at " & drTxt("Number of
characters").ToString() & " characters")
exit do
finally
end try
Loop
drTxt.Close()
conTxt.Close()
Here's some code to generate the CSV file that causes the error:
dim i as integer
dim strDescription as string
for i = 1 to 2000
strDescription = strDescription & "a"
next
response.write(vbcrlf & """Number of characters"", ""Description""" &
vbcrlf)
for i = 1 to 1000
strDescription = strDescription & "a"
response.write(len(strDescription) & ", """ & strDescription & """" &
vbcrlf)
next
And here's the error message that occurs when the number of characters
in the description field of the CSV reaches 2047 chars:
NO_DATA - no error information available
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Data.Odbc.OdbcException: NO_DATA - no error
information available
Source Error:
Line 53: Do While drTxt.Read()
Line 54: 'try
Line 55: response.write("<br>" & drTxt("Number of
characters").ToString() & " " & drTxt("Description").ToString())
Line 56: 'catch
Line 57: response.write("<br>Error at " & drTxt("Number of
characters").ToString() & " characters")
Thanks very much to anyone who can shed any light on this.
Simon
ODBCDataReader to read from a CSV file.
Most of the time it works, but if the "description" field contains more
than 2046 chars, I get a NO_DATA error (see below for full error) when
trying to read that row. If this field contains 2046 chars or less,
then everything works fine.
There are about 6800 rows or lines in the CSV file. However, if I
reduce the amount of lines in the CSV to, say 25, then the description
field can contain more than 2046 chars without causing the error.
Here's a sample from my code:
'Save uploaded file to disk.
filCSV.PostedFile.SaveAs(server.MapPath("import/properties.csv"))
'Import data from CSV into MSSQL.
dim strTxtConString as string = "Driver={Microsoft Text Driver (*.txt;
*.csv)};Dbq=" & Server.MapPath("import/") & ";"
dim conTxt as ODBCConnection = New ODBCConnection(strTxtConString)
dim cmdTxt as ODBCCommand
dim drTxt as ODBCDataReader
conTxt.Open()
cmdTxt = conTxt.CreateCommand()
cmdTxt.CommandText = "SELECT * FROM [properties.csv]"
cmdTxt.CommandType = CommandType.Text
drTxt = cmdTxt.ExecuteReader()
Do While drTxt.Read()
try
response.write("<br>" & drTxt("Number of characters").ToString() & "
" & drTxt("Description").ToString())
catch
response.write("<br>Error at " & drTxt("Number of
characters").ToString() & " characters")
exit do
finally
end try
Loop
drTxt.Close()
conTxt.Close()
Here's some code to generate the CSV file that causes the error:
dim i as integer
dim strDescription as string
for i = 1 to 2000
strDescription = strDescription & "a"
next
response.write(vbcrlf & """Number of characters"", ""Description""" &
vbcrlf)
for i = 1 to 1000
strDescription = strDescription & "a"
response.write(len(strDescription) & ", """ & strDescription & """" &
vbcrlf)
next
And here's the error message that occurs when the number of characters
in the description field of the CSV reaches 2047 chars:
NO_DATA - no error information available
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Data.Odbc.OdbcException: NO_DATA - no error
information available
Source Error:
Line 53: Do While drTxt.Read()
Line 54: 'try
Line 55: response.write("<br>" & drTxt("Number of
characters").ToString() & " " & drTxt("Description").ToString())
Line 56: 'catch
Line 57: response.write("<br>Error at " & drTxt("Number of
characters").ToString() & " characters")
Thanks very much to anyone who can shed any light on this.
Simon