使用MSSQL Server从MS ACCESS数据库中选择数据记录

时间:2015-12-22 07:25:38

标签: sql-server ms-access ms-access-2010

我已经从其他工作站成功创建了一个链接,我可以查看MS ACCESS数据库中的所有表。但我无法使用简单的SELECT语句从表中检索数据。

SELECT * FROM [192.168.1.64].default.dbo.CHECKINOUT;

当我执行此查询时出现此错误:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'default'.

我也发现了这个问题:

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO

SELECT a.*
FROM OPENROWSET('SQLNCLI', 'Server=192.168.1.64;Trusted_Connection=yes;',
     'SELECT *
      FROM default.dbo.CHECKINOUT') AS a;
GO

但得到了这个错误:

Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install.
Configuration option 'Ad Hoc Distributed Queries' changed from 1 to 1. Run the RECONFIGURE statement to install.
OLE DB provider "SQLNCLI10" for linked server "(null)" returned message "Login timeout expired".
OLE DB provider "SQLNCLI10" for linked server "(null)" returned message "A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.".
Msg 1231, Level 16, State 1, Line 0
Named Pipes Provider: Could not open a connection to SQL Server [1231]. 

Configured Linked Server

1 个答案:

答案 0 :(得分:1)

在SQL Server中创建指向Access数据库的链接服务器时,我们引用特定的数据库文件,因此" catalog"和"架构"在这种情况下没有实际意义。因此,在T-SQL中将Access表指定为四部分名称时,我们只省略第二部分和第三部分:

SELECT * FROM [AccessLinkedServerName]...[TableName]

或者,在您的情况下

SELECT * FROM [192.168.1.64]...[CHECKINOUT]