[MSSQL] 透过OPENROWSET读取EXCEL

Posted petewell

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[MSSQL] 透过OPENROWSET读取EXCEL相关的知识,希望对你有一定的参考价值。

...


STP1. 开启Server>Facets>SurfaceAreaConfiguration>AdHocRemoteQueriesEnabled, 若未开启错误消息如下,

Msg 15281, Level 16, State 1, Line 1
SQL Server blocked access to STATEMENT ‘OpenRowset/OpenDatasource‘ of component ‘Ad Hoc Distributed Queries‘ because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of ‘Ad Hoc Distributed Queries‘ by using sp_configure. For more information about enabling ‘Ad Hoc Distributed Queries‘, see "Surface Area Configuration" in SQL Server Books Online.


sp_configure ‘show advanced options‘,1;
GO
RECONFIGURE;
GO
sp_configure ‘Ad Hoc Distributed Queries‘,1;
GO
RECONFIGURE;
GO

技术图片

STP2. MyComputer>Manage>Services>SQLServer(MSSQL)>Properties>LogOn, 以管理员账号密码登入MSSQL, 重启Service, 否则会出现拒绝存取的错误

技术图片

技术图片

STP3. 若是32 bit WIN?OS + 32 bit Office 2003, 确认Microsoft.Jet.OLEDB.4.0存在Server>ServerObjects>LinkedServers>Providers, OPENROWSET读取EXCEL语法如下,


SELECT * FROM OPENROWSET(‘Microsoft.Jet.OLEDB.4.0‘, ‘Excel 8.0;Database=D:Book1.xls‘,‘SELECT * FROM [Sheet1$]‘)

技术图片

STP3. 若是64 bit WIN?OS + 64 bit Office 2010, 确认Microsoft.ACE.OLEDB.12.0存在Server>ServerObjects>LinkedServers>Providers, OPENROWSET读取EXCEL语法如下,


SELECT * FROM OPENROWSET(‘Microsoft.ACE.OLEDB.12.0‘, ‘Excel 12.0;Database=D:Book1.xls‘, ‘SELECT * FROM [Sheet1$]‘);

技术图片

TS1. 64 bit OS不支持Microsoft.Jet.OLEDB.4.0, 错误消息如下,

Msg 7308, Level 16, State 1, Line 1
OLE DB provider ‘Microsoft.Jet.OLEDB.4.0‘ cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.

原文:大专栏  [MSSQL] 透过OPENROWSET读取EXCEL


以上是关于[MSSQL] 透过OPENROWSET读取EXCEL的主要内容,如果未能解决你的问题,请参考以下文章

如何在 mssql 服务器视图中查询访问表

sql sever读取Excel总结

java的poi 读取exc 文件

读取 NSFetchedResultsController 的 fetchedObjects 属性时出现 EXC_BAD_ACCESS 错误(仅在模拟器上)

MSSQL 和 JDBC 读取 DBCC USEROPTIONS

java.lang.NullPointerException 使用火花从 MSSQL 服务器读取数据