2

我收到此错误:

system.data.sqlclient.sqlexception 超时已过期。在操作完成之前超时时间已过或服务器没有响应。

代码:

    Dim ExcelConnection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\z.fontanilla\Documents\etl.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=Yes""")

    ExcelConnection.Open()

    Dim expr As String = "SELECT * FROM [Sheet1$]"
    Dim objCmdSelect As OleDbCommand = New OleDbCommand(expr, ExcelConnection)

    Dim objDR As OleDbDataReader

    Dim SQLconn As New SqlConnection()
    Dim ConnString As String = "Data Source=cyayay\sqlexpress;Initial Catalog=reportingDB;Integrated Security=True"
    SQLconn.ConnectionString = ConnString
    SQLconn.Open()


    Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(SQLconn)
        bulkCopy.DestinationTableName = "tFalse"

        Try
            objDR = objCmdSelect.ExecuteReader
            bulkCopy.WriteToServer(objDR)
            objDR.Close()
            SQLconn.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Using
    ExcelConnection.Close()
4

1 回答 1

1

您可以尝试将 objCmdSelect 对象上的 CommandTimeout 属性设置为 700(或其他)值。

于 2013-10-04T16:23:14.550 回答