簡體   English   中英

使用MSSQL Server從MS ACCESS數據庫中選擇數據記錄

[英]SELECT data records from MS ACCESS database using MSSQL Server

我已經從其他工作站成功創建了鏈接,並且可以從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 Server中創建指向Access數據庫的鏈接服務器時,我們引用的是特定的數據庫文件,因此“目錄”和“模式”在此上下文中沒有實際含義。 因此,在T-SQL中將Access表指定為四部分名稱時,我們只需省略第二和第三部分:

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

或者,就您而言

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM