SELECT 使用 MSSQL Server 从 MS ACCESS 数据库中获取数据记录
SELECT data records from MS ACCESS database using MSSQL Server
我已经从其他工作站成功创建了 link,我可以从 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].
在 SQL 服务器中创建指向 Access 数据库的链接服务器时,我们引用特定的数据库文件,因此 "catalog" 和 "schema" 在该上下文中没有实际意义.因此,当在 T-SQL 中将 Access table 指定为由四部分组成的名称时,我们只需省略第二部分和第三部分:
SELECT * FROM [AccessLinkedServerName]...[TableName]
或者,在您的情况下
SELECT * FROM [192.168.1.64]...[CHECKINOUT]
我已经从其他工作站成功创建了 link,我可以从 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].
在 SQL 服务器中创建指向 Access 数据库的链接服务器时,我们引用特定的数据库文件,因此 "catalog" 和 "schema" 在该上下文中没有实际意义.因此,当在 T-SQL 中将 Access table 指定为由四部分组成的名称时,我们只需省略第二部分和第三部分:
SELECT * FROM [AccessLinkedServerName]...[TableName]
或者,在您的情况下
SELECT * FROM [192.168.1.64]...[CHECKINOUT]