I need to import some datafrom a Excel worksheet but the OleDbConnection is using the 32bit version, so it cant find the provider. I already imported using the 64bit wizzard and everything is working fine.
Already tried using the following connection string:
Provider=Microsoft.ACE.OLEDB.12.0;
Public Shared Function ExcelToSqlServer() As Integer
Dim ds As New DataSet
Dim da As New OleDbDataAdapter
Dim conn As New OleDbConnection
Dim cnn As New SqlConnection
Dim sqlBC As SqlBulkCopy
Dim myFileDialog As New System.Windows.Forms.OpenFileDialog
Dim xSheet As String = ""
With myFileDialog
.Filter = "Excel Files |*.xlsx"
.Title = "Open File"
.ShowDialog()
End With
If myFileDialog.FileName.ToString <> "" Then
Dim ExcelFile As String = myFileDialog.FileName.ToString
xSheet = "Incidentes"
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & "data source=" & ExcelFile & "; " & "Extended Properties='Excel 12.0 Xml;HDR=Yes'")
Try
conn.Open()
da = New OleDbDataAdapter("SELECT * FROM [" & xSheet & "$]", conn)
ds = New DataSet
da.Fill(ds)
sqlBC = New SqlBulkCopy(cnn)
sqlBC.DestinationTableName = "Incidentes"
sqlBC.WriteToServer(ds.Tables(0))
conn.Close()
Return 1
Catch ex As Exception
MsgBox("Error: " + ex.ToString, MsgBoxStyle.Information, "Informacion")
conn.Close()
Return -1
End Try
End If
Return -1
End Function
I get the following error when I run this function