Domanda SQLBulkCopy not working IIS7

  • lunedì 2 aprile 2012 16:33
     
     

    I don't know which forum to post this to but could someone please tell me what I need to do to make this work in IIS7?  It was working fine in IIS6. Thanks!

                Try
      
                    Dim sSQLTable As String = "tempContainer"
                    Dim sExcelFileName As String 
                    Dim sWorkbook As String           
                    Select Case ddlfilter.selecteditem.text
                        Case "Receive"                     
                            sExcelFileName = "receive.xls"
                            sWorkbook = "[receive$]"
                        Case "Move"                     
                            sExcelFileName = "move.xls"
                           sWorkbook = "[move$]"
                        Case "Repair"                     
                            sExcelFileName = "repair.xls"
                            sWorkbook = "[repair$]"
                        Case "Ship"                     
                            sExcelFileName = "ship.xls"
                            sWorkbook = "[ship$]"                                                                        
                    End Select  
        
                    'Create our connection strings 
                    Dim sExcelConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(sExcelFileName) & ";Extended Properties=""Excel 8.0;HDR=NO;"""
                    'Dim sSqlConnectionString As String = WebConfigurationManager.ConnectionStrings("DSN").ToString 
                     
                    'Execute a query to erase any previous data from our temp destination table 
                    Dim sClearSQL = "DELETE FROM " & sSQLTable 
                    'Dim SqlConn As SqlConnection = New SqlConnection(sSqlConnectionString) 
                    Dim SqlCmd As SqlCommand = New SqlCommand(sClearSQL, SqlConn) 
                    SqlConn.Open() 
                    SqlCmd.ExecuteNonQuery() 
                    SqlConn.Close() 
                     
                    'Series of commands to bulk copy data from the excel file into our SQL table 
                    Dim OleDbConn As OleDbConnection = New OleDbConnection(sExcelConnectionString) 
                    Dim OleDbCmd As OleDbCommand = New OleDbCommand(("SELECT * FROM " & sWorkbook), OleDbConn) 
                    OleDbConn.Open() 
                    Dim dr As OleDbDataReader = OleDbCmd.ExecuteReader() 
                    Dim bulkCopy As SqlBulkCopy = New SqlBulkCopy(ConfigurationSettings.AppSettings("DSN")) 
                    bulkCopy.DestinationTableName = sSQLTable 
                    bulkCopy.WriteToServer(dr) 
                    OleDbConn.Close()

Tutte le risposte