January 25, 2013 at 3:53 pm
In our development environment web application we're uploading excel files to the SQL server and importing them using openrowset. This was working fine. We reinstalled on another SQL server and the web app stopped working (all other DB related functionality still worked).
Log in via SSMS and run the command as SA, works great. As any other user you get the OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "Unspecified error".
Can someone please help? The command obviously works on the server, just not as any user other than SA. I've tried changing permissions on the source folder, the SQL temp directory... Man, I'm stuck.
Thanks
January 25, 2013 at 4:19 pm
"Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "Unspecified error".
Check the security settings for the linked server. Is security set to "without security context", ""login's current security context", or "this security context"?
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
January 25, 2013 at 4:23 pm
You also may wish to check out these links:
http://stackoverflow.com/questions/9687631/openrowset-with-excel-file
And also make sure the file isn't currently open while running your process, this error can pop up if the file is open while it attempts to access it!
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
January 25, 2013 at 4:29 pm
How can I check the security context? There is no linked server because we;re using openrowset.
I looked at stack - I would think if it was trying to access a folder that doesn't exist it would fail for the SA account as well. Same with the SP reconfigure statements. We've run those once. They should be for the server, correct? I see that they create registry entries.
Thanks for the response!
ST
January 25, 2013 at 4:43 pm
Um...no linked server? Are you certain? I am under the impression you can't import data from EXCEL without using a linked server or some System DSN (which then would still point to a linked server).
I mean via SSMS, how would SQL be made aware of a file from the filesystem?
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
January 25, 2013 at 4:47 pm
We're running this in a stored procedure:
SELECT
myFields FROM
OPENROWSET(
'Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=\\myServer\UploadedFile\WorkLoad_Dist.xlsx', [Sheet1$])
I've also used a direct path to the file system. It works for SA, it works for a public account, it fails for a domain user account that has sysadmin permissions.
I looked under linked servers, all I have is a provider folder
Totally stumped.
January 25, 2013 at 5:22 pm
Oh ok, gotcha - very true, linked server not needed here...all I can suggest is that you need to verify that domain users have access to the file folder being accessed 🙁
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
January 25, 2013 at 5:31 pm
I take that suggestion back!
Verify these things are true:
1. Install Office 2007 Data Connectivity Components (http://www.microsoft.com/download/en/confirmation.aspx?id=23734) - which I'm sure is already installed as it currently works when runing as 'sa'
2. Ensure "Ad Hoc Distributed Queries" is enabled on the server this is running on - you can turn this on by running:EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1 GO
3. Change your OPENROWSET query to be:
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=\\myServer\UploadedFile\WorkLoad_Dist.xlsx;HDR=Yes','SELECT * FROM [Sheet1$] ')
I was getting the same issue you were running running it as myself (sysadmin) when connecting as my windows authentication. After verifying the things above, it worked.
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
January 26, 2013 at 7:35 am
Thank you. I thought about that when I woke up this morning, that making the SQL call in a string will cause the execution to be done by the SQL account and not the account that is running the query. I'll check and let you know.
Thanks
ST
January 26, 2013 at 7:58 am
No joy.
I'm wondering if it's caused my the domain permissions. I can create a public user with no special privileges on the SQL server and perform this operation with no problem. connecting using windows authentication, even as an admin user, no joy.
Thanks for the help. I'm not giving up... yet
ST
January 26, 2013 at 7:49 pm
Long time no see, ST.
Who is the actual database owned by? If it's (hopefully) someone with "SA" privs, try adding WITH EXECUTE AS OWNER to the stored procedure and give the user privs just to execute the stored procedure (if they can't already).
--Jeff Moden
Change is inevitable... Change for the better is not.
January 27, 2013 at 12:31 pm
Hi, Jeff. Nice to hear from you again as well.
I tried your approach. It didn't work but may shed light on the overall issue. I get the following error:
Access to the remote server is denied because the current security context is not trusted.
Any thoughts?
ST
January 28, 2013 at 12:36 pm
To anyone else who felt this pain here's the solution. First of all, ProcessMon is your friend. Seems that in Win Server2008 SQL Server 2008 R2 was impersonating the login that was initiating the process. My spreadsheet was being copied to:
C:\Windows\ServiceProfiles\NetworkService\AppData\Local\temp
Allowing my web server to read/write to this directory solved the issue.
Whew!
ProcessMon
January 28, 2013 at 1:05 pm
Interesting! I thought running the script to "Allow In Process" would have fixed that - good to know when dealing with a web server 🙂
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
January 29, 2013 at 5:14 am
It IS interesting.
Basically, if the user running the script or procedure is a DB user, the network service account (or whatever the SQL Server is running as) does the work. It has access to the directory.
However, if the account is a windows account, SQL impersonates that user. If you have multiple users that need access to the server and the process, you can put them all in a group and add permissions to the group.
My fear is that this solution is fragile. What if, in a SQL upgrade, the "working directory" is changed? The solution fails. I looked for a way to NOT have the proc impersonate the user but couldn't find it. I looked into EXECUTE AS but it specifically doesn't allow you to execute as network service. I didn't look as far as mapping to a credential. That may be an approach that I try.
ST
Viewing 15 posts - 1 through 15 (of 20 total)
You must be logged in to reply to this topic. Login to reply