Public Sub Main()
Dim connSource As New System.Data.Odbc.OdbcConnection
Dim cmdSource As New System.Data.Odbc.OdbcCommand
Dim cmdupdate As New System.Data.Odbc.OdbcCommand
Dim connsql As System.Data.Odbc.OdbcConnection
Dim cmdsql As System.Data.Odbc.OdbcCommand
connsql = New System.Data.Odbc.OdbcConnection
strsqlConnectionString = "Driver={ODBC Driver 11 for SQL Server};" & _
"Server=MyDatabaseServer;" & _
"DataBase=MyDatabase;" & _
"Trusted_Connection=Yes;"
connsql.ConnectionString = strsqlConnectionString
connsql.Open()
cmdSource.Connection = connSource
cmdupdate.Connection = connsql
cmdsql = New System.Data.Odbc.OdbcCommand
Dim m_strSourceExcelFileName As String
m_strSourceExcelFileName = Dts.Variables("User::FileName").Value.ToString()
Dim m_strSourceFilePath As String = "D:\Files\2017\"
m_strConnSource = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + m_strSourceFilePath + "\" + m_strSourceExcelFileName + "; Extended Properties='Excel 12.0 Xml;HDR=NO'"
connSource.ConnectionString = m_strConnSource
connSource.Open()
我在SSIS脚本任务中有上面的代码片段。脚本任务包含将读取数据从Excel复制到SQL Server 2014的代码。
我在上面的代码段中的最后一行'connSource.Open()'
收到以下错误。
错误[IM002] [Microsoft] [ODBC驱动程序管理器]未找到数据源名称且未指定默认驱动程序
我似乎无法弄清楚我的连接字符串有什么问题。我在机器上安装了AccessDatabaseEngine_x64.exe。
答案 0 :(得分:0)
要使用ODBC连接到Excel,我使用连接字符串,如:
Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=E:\foo\excelTest.xls;
适用于ACEODBC.DLL
附带的驱动程序,日期为22.03.2010