简体   繁体   English

带有 Excel 2016 的 SQL Server 2017 OPENROWSET

[英]SQL Server 2017 OPENROWSET with Excel 2016

I am completely baffled by SQL Server and OPENROWSET permissions.我完全被 SQL Server 和OPENROWSET权限搞糊涂了。

Our team has an AD Group.我们的团队有一个 AD 组。 This group is included in the DEV server's Windows Administrators local group.该组包含在 DEV 服务器的 Windows 管理员本地组中。 This same AD group has SysAdmin privilege on the local installation of SQL Server 2017.该 AD 组对 SQL Server 2017 的本地安装具有 SysAdmin 权限。

Attempting to run the command:尝试运行命令:

SELECT *  
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=C:\Work\test.xls;HDR=YES',['sheet1$'])

works for me, but for none of my teammates.对我有用,但对我的队友都不适用。

If there is a definitive document on the security requirements for using the OPENROWSET command - I have not found it (and please - don't refer me to docs.microsoft.com - that documentation is not written in any way that I understand).如果有关于使用OPENROWSET命令的安全要求的明确文档 - 我还没有找到它(并且请 - 不要将我推荐给 docs.microsoft.com - 该文档不是以我理解的任何方式编写的)。

There are other issues I have found including if I change the name of the sheet in the Excel workbook - the command fails (and yes - I closed the book after making the change).我发现了其他问题,包括如果我更改 Excel 工作簿中工作表的名称 - 命令失败(是的 - 我在进行更改后关闭了这本书)。

Finally - some feedback on the use of OPENROWSET - is it generally a good idea?最后 - 关于使用OPENROWSET一些反馈 - 这通常是一个好主意吗? a bad idea?一个坏主意? pretty much neutral but be prepared for these kinds of problems?几乎是中立的,但要为这些问题做好准备吗?

I hope this question is specific enough to be answered - I have probably spent 20+ hours trying to figure out how to understand how this works so I can make it work and use it consistently.我希望这个问题足够具体,可以回答——我可能花了 20 多个小时试图弄清楚如何理解它是如何工作的,这样我才能让它工作并始终如一地使用它。

Thanks!谢谢!

So honestly troubleshooting security/permissions and errors with SQL Server is probably the most frustrating aspects of my job.所以老实说,解决 SQL Server 的安全/权限和错误可能是我工作中最令人沮丧的方面。

First few questions and thoughts about your dilemma.关于您的困境的前几个问题和想法。

  • Do you really want to be granting your team connected to your db sysadmin rights?你真的想授予你的团队连接到你的数据库系统管理员权限吗? I wouldn't do that period, full-stop.我不会做那个时期,句号。
  • Will the data be refreshed?数据会刷新吗? If yes, I suggest you ingest this data into a sql table with a process, perhaps python, ssis, dts package, powershell, whatever you fancy.如果是,我建议您将这些数据摄取到带有进程的 sql 表中,可能是 python、ssis、dts 包、powershell,无论您喜欢什么。

If the data will always be static in that one excel file, I'd suggest perhaps making it act like a linked server for (hopefully) fewer permission issues?如果数据在那个 excel 文件中始终是静态的,我建议也许让它像一个链接服务器一样(希望)更少的权限问题? Also, it's easier to query that way, from my memory.此外,根据我的记忆,以这种方式查询更容易。

In any event, this article (non msdn link) may help?无论如何,这篇文章(非 msdn 链接)可能会有所帮助? I've done it this way once before and had slightly less of a difficult time, but then again it involves adding a driver (usually) to the sql server.我以前用这种方式做过一次,而且难度略低,但它又涉及向 sql 服务器添加驱动程序(通常)。 BUT, then I did not have to allow multiple users sysadmin - and I think ANYTHING is better than that.但是,那么我不必允许多个用户 sysadmin - 我认为任何事情都比这更好。

https://www.sqlshack.com/query-excel-data-using-sql-server-linked-servers/ https://www.sqlshack.com/query-excel-data-using-sql-server-linked-servers/

Sometimes the issue is not with the user running the query, but SQL Server using the account it runs as - to get permissions on the file.有时问题不在于运行查询的用户,而在于 SQL Server 使用它运行的帐户 - 获取对文件的权限。 This article goes over that aspect as well.这篇文章也讨论了这方面。 I'm not sure that is your issue as you say it works for me but not for thee , but maybe read that portion of the article at least?我不确定那是你的问题,因为你说它对我有用但对你不起作用,但也许至少阅读文章的那部分?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM