将数据从本地访问表传输到链接的SQL Server表

问题描述:

我想找到一种有效的解决方案,将数据从本地Access表移动到Linked SQL Server表中。  通过Access运行简单的附加功能已被证明是一个糟糕的解决方案,运行时间超过10万分钟,大约有200,000条记录。
 

I would like to find an efficient solution to moving data from a local Access table into a Linked SQL Server table.  Running a simple Append through Access has proven to be a terrible solution, with a 10+ minute run time for about 200,000 records.  

我正在研究创建一个存储过程,它将本地Access表作为表值参数接收,然后将所有这些记录插入到SQL表中。  我创建了以下存储过程:

I am looking into creating a stored procedure that will take in the local Access table as a table valued parameter, then insert all of those records into the SQL table.  I have created the following stored proc:

CREATE TYPE MOR.RMAZATableType AS TABLE (
	PostingDate smalldatetime,
	RMA varchar(12));
go



CREATE PROCEDURE MOR.USP_InsertRMAData
	@TVP RMAZATableType READONLY
	AS

Set NOCOUNT ON
Insert Into mor.tblRMAZA (PostingDate,RMA)
SELECT * FROM @TVP
Return;
Go

我是SQL Server的新手,所以我相信上面可能有错误。  

I am fairly new to SQL Server, so I believe there is probably an error in the above.  

然后尝试通过Access中的存储过程调用传递匹配的记录集:

I then attempt to pass the matching recordset via stored procedure call in Access:

Sub USP_InsertTest(rst As Recordset)
  Dim conn As New ADODB.Connection, cmd As New ADODB.Command
  Set conn = OpenSQLConnection
  Set cmd = OpenStoredProc("MOR.usp_InsertRMAData", conn)
  cmd("@TVP") = rst     <----------------------
  cmd.Execute
  Set cmd = Nothing
  CloseSQLConnection conn
End Sub

我在这里收到错误(cmd(" @ TVP")= RST)。  "参数类型错误,超出可接受的范围,或彼此冲突。"

I get an error here (cmd("@TVP") = rst).  "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."

请帮助!!

我正在使用SSMS 2012和MS Access 2010。

I am using SSMS 2012 and MS Access 2010.

基于错误信息,这意味着RecordSet超出了可接受的范围,在我看来,我们无法访问存储的记录集对象程序。

Base on the error message, it means the RecordSet is out of acceptable range, in my opinion, we can’t access the recordset object on the stored procedure.

对于此要求,我建议您使用SQL Server导入和导出向导将数据导入SQL Server数据库的简单方法。

For this requirement, I suggest that the simple way is that you could use SQL Server import and export wizard to import data to the SQL Server database.

#运行SQL Server导入和导出向导

https://msdn.microsoft.com/en-us/library/ms140052(v = sql.110).aspx

另一方面,您可以尝试通过带有OPENDATASOURCE语法的SQL语句来实现这一点。

On the other hand, you could try to achieve that through the SQL statement with OPENDATASOURCE syntax.

OPENDATASOURCE(Transact-SQL)

# OPENDATASOURCE (Transact-SQL)

https://msdn.microsoft.com/en-IN/library/ms179856.aspx

问候

Starain