2014-05-20 2 views
0

Excel 파일을 업로드하고 ASP.net 응용 프로그램의 SQL 서버 테이블에 저장하려고하면 다소 이상한 문제가 있습니다. 파일 크기가 너무 크지 않습니다 (약 2.5MB 또는 3MB). 문제는로드 프로세스가 I 클라이언트에 보내고있다 성공 메시지를 표시하여 완료 이후 업로드, appearently 특정 오류를 발생시키지 않고, 일부 행을로드 한 후 "중단"도착한다는 것입니다 :Asp.net : Excel 파일 업로드가 완료되지 않고 오류 메시지가 표시되지 않습니다.

의 " 프로세스가 성공적으로 완료되었습니다 : XXX 행이 파일에서 업로드되었습니다. "

문제는 XXX 행이 파일의 모든 행이 아니라는 것입니다. Excel 파일의 각 열에 얼마나 많은 정보가 있는지에 따라 프로세스는 파일이 가지고있는 총 25000 개에서 15500 개의 행만 업로드합니다. (Excel 파일에 정보가 적 으면 업로드 할 수 있으며, 25,000 행 중 20000 개를 업로드 할 수 있습니다.) 사실 파일이 "완전히"업로드되고 있지 않습니다.

파일이 ASP.net에있는 기본 4MB 파일 업로드보다 크지는 않지만 이미 web.config에서 "httprequest-maxRequestLength" 값을 늘려 보았습니다.

Dim connection As DbConnection = Nothing 
Dim Command As DbCommand = Nothing 
Dim ConexionStringExcel As String 
Dim dr As DbDataReader 
Dim mensajeError as String = "" 
Dim ncAdic as Integer = 0 
Dim nReg as Integer = 0 

'String connection for Excel 2007: for now, I'm not allowing other Excel versions 
ConexionStringExcel = "Provider=Microsoft.ACE.OLEDB.12.0;" & _ 
    "Data Source = " & sNombreArch & ";" & _ 
    "Extended Properties=Excel 12.0 Xml;" 

'sNombreArch is the full name of the uploaded file 

connection = New OleDb.OleDbConnection(ConexionStringExcel) 

Command = connection.CreateCommand() 

Command.CommandText = "SELECT * FROM [" + nomHojaArch + "$]" 

'--- 
'lblMensaje is a Label object in the aspx page: 
'--- 
lblMensaje.Visible = False 

Try 
    'Open the Excel file 
    connection.Open() 
    'Read file content 
    dr = Command.ExecuteReader() 

    While dr.Read 
     Try 
      'Two first columns of the file are mandatory in my case... 
      If Not IsDBNull(dr(0)) And Not IsDBNull(dr(1)) Then 
       '--- 
       'dsTempCargue is a SqlDataSource object in the aspx page 
       '--- 
       dsTempCargue.InsertParameters.Item("idReg").DefaultValue = dr(0) 
       dsTempCargue.InsertParameters.Item("nombre").DefaultValue = dr(1) 

       For ncAdic = 2 To 10 
        If Not IsDBNull(dr(ncAdic)) Then 
         dsTempCargue.InsertParameters.Item(ncAdic).DefaultValue = dr(ncAdic) 
        Else 
         dsTempCargue.InsertParameters.Item(ncAdic).DefaultValue = DBNull.ToString 
        End if 
       Next 

       dsTempCargue.Insert() 

               nReg = nReg + 1 
      Else 
       mensajeError = "Column A and B of the File cannot be empty" 
       Exit While 
      End If 
     Catch exRead As Exception 
      mensajeError = "Error reading the file or saving its content: " & exRead.Message 
      Exit While 
     End Try    
    End While 

    'If there was no error, show success message 
    If String.IsNullOrEmpty(mensajeError) Then 
     mensajeError = "The process finished successfuly. " & nReg.ToString() & " rows were uploaded from the file" 
    End IF 
Catch ex As Exception 
    mensajeError = "Error uploading the file: " & ex.Message   
End Try 

lblMensaje.Text = mensajeError 
lblMensaje.Visible = True 

왜이 업로드 프로세스가 전체 파일을 읽을 실패 생각하십니까 ??? .. : 내가 업로드를 사용하여 파일을 읽을 수있어 코드 (vb.net)는 기본적으로,이입니다 어떤 조언을 주시면 감사하겠습니다.

고마워,

디에고 당신이 어떤 데이터 타입은 다양한 열이있는 행을 저장하는 테이블의

답변

0

? 아마도 셀 중 하나의 내용이 열 데이터 유형과 호환되지 않습니다. 어떤 방법으로 검사 할 수 있니?

+0

감사 패트릭 답변에 대한 ... 그러나, 나는 이미 관심 (나는 약간의 시간이있을 때 아마도 내가 가진이 문제에 대한 자세한 정보를 찾을하려고합니다) 내 SQL 테이블의 데이터 유형 대 Excel 파일의 정보를 확인하고 아무런 이상이 없음을 발견했습니다. 내 SQL 테이블 (및 파일)의 첫 번째 열은 int 열이고 나머지는 문자열 (varchar) ... My App. 항상 정보의 양을 잘 읽고 있습니다 : Excel 파일에있는 정보의 양에 따라 프로세스가 더 적은 행을 업로드합니다 (원래의 질문을 읽어주십시오) ... "제한"매개 변수가 httprequest-maxRequestLength)를 구성해야합니까? 다른 아이디어? – DiegoGB

+0

동일한 파일을 여러 번 업로드 할 때 동일한 양의 행이 삽입됩니까? –

+0

네, 맞습니다 : 똑같은 파일을 올리면 삽입 된 행의 수가 항상 같습니다 ... 단서가 있습니까? ... 고마워요 – DiegoGB

0

오류의 원인이 무엇인지 확신 할 수는 없지만 마침내 그 코드를 변경하여 제 3 자 라이브러리를 사용하여 찾았습니다. 좋은 의견이 있습니다. , 이는 여기에 있습니다 :

http://exceldatareader.codeplex.com/

내가 원래 문제가 있었고,이 라이브러리를 사용하는 이유를하면 문제를 해결하지만, 그것은 일 일에 대해 정말 모르겠어요.

감사 패트릭 귀하의 의견에 대한 모든

관련 문제