I've several entries for this kind of problem, and none of them seem to solve it for me.
My SQL SERVER and SQL SERVER AGENT services are both set to the same user account.
I have a stored procedure which does the following (error-checking cruft removed)
exec XP_CMDSHELL 'net use P: \\machine/share password /user:machine\user'
exec XP_CMDSHELL 'dir p: /b /a-d-h-s > p:\dir.txt'
CREATE TABLE #FilesTemp ( Filename varchar(200) )
BULK INSERT #FilesTemp
FROM 'p:\dir.txt'
WITH
(
ROWTERMINATOR = '\n'
)
When I run the stored procedure from SSMS, it runs fine. When I run it via a job, the XP_CMDSHELL calls work properly and the 'dir.txt' file is created. But the bulk insert fails with an error 3 (p:\dir.txt not found).
I'm logged into SSMS, connected to the SQL Server using 'sa' and the job is owned by sa. The user the share is being created as has the necessary permissions.
MORE INFORMATION:
There was a comment placed (and then apparently deleted) asking if I was running SSMS from the server machine or not. I tried it.
Apparently, when I run using Windows Authentication, the bulk insert fails, but when running stored procedure as SA, it works. The Agent is running using Windows Authentication and fails.
But why? I'm at a loss to understand the security issue.
Any thoughts?