将数据从Access链接到SQL Server

时间:2017-08-28 21:03:00

标签: sql-server ms-access

我们有一个可靠运行的Access数据库和用户界面。 accdb文件存储在我的SQL Server可见的网络驱动器上。我想将这些数据链接到我的SQL Server。在Access数据库中发生的CRUD(通过Access UI),我想在SQL数据库中显示。在这种情况下,Access DB是主服务器,SQL Server是从服务器。这可能吗?

由于

2 个答案:

答案 0 :(得分:1)

您可以通过 ODBC 将SQL Server表链接到Access应用程序。

然后,在此,创建查询和/或代码,将Access表中的数据附加/更新到SQL Server表。

答案 1 :(得分:0)

我认为通常是相反的做法;访问FE和SQL Server BE,但是,你可以按照你描述的方式进行访问。

你应该首先考虑一些基本的事情。

https://www.mssqltips.com/sqlservertip/2484/import-data-from-microsoft-access-to-sql-server/

https://support.office.com/en-ie/article/Import-or-link-to-data-in-an-SQL-Server-database-a5a3b4eb-57b9-45a0-b732-77bc6089b84e

现在,要推送或拉取数据,请创建存储过程并从Access中获取所需内容。

CREATE PROCEDURE dbo.uspCopyTable
AS

INSERT INTO
dbo.mytable (myfield)

SELECT
myfield
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'c:\mypath\mydb.mdb';'admin';'mypwd', mytable)
GO

fire it off by something like this

dim cn as adodb.connection
set cn = new adodb.connection
cn.open "Provider=sqloledb;" & _
"Data Source=myServerName;" & _
"Initial Catalog=myDatabaseName;" & _
"Integrated Security=SSPI"
cn.execute "dbo.uspCopyTable"

或者,使用VBA将数据从Access推送到Excel。

Make new table:
Dim strsql As string
strSql = "SELECT * Into YourNewAccessTableName FROM ExistingSqlTableName"
Currentdb.execute(strSql)
Insert into existing Access table (assume fieldnames are the same:

Dim strsql As string
strSql = "INSERT Into YourAccessTableName SELECT * FROM ExistingSqlTableName"
Currentdb.execute(strSql)