Reputation: 571
We have some code that we want to run a BULK INSERT sql command, but it's getting access denied because the account SQLAgent is installed as doesn't have permissions to the folder the file is in. I don't want that account to have permissions to that folder, and would love to use a proxy account if I could instead.
Don't think this helps much, but here's the vb code we're using to run the sql command:
Dim sql As String = "BULK INSERT Visa From '@file' With (ROWTERMINATOR = '\n', FIELDTERMINATOR = '\t', KEEPNULLS)"
sql = Replace(sql, "@period", _date)
sql = Replace(sql, "@file", FullPath)
DBExecute(sql)
How to get this to work?
Upvotes: 1
Views: 661
Reputation: 2655
As HardCode wrote, You can use RunAs for each job step. Basically, You have to:
Note that credentials You use has to have permissions to access the folder as well as permissions to connect to databse. Later is not needed if You use SQL Server login instead of Windows Authentication in your VB.NET code.
Here You can find step by step instructions on how to add credentials and proxy.
UPDATE: your comment shed some light on original question. You didn't want to change job step proxy/credentials but to use .NET to impersonate user.
You can achieve this by:
Upvotes: 1