microsoft / microsoft/sql-server-samples

Access Denied while running Python script from SQL Server

Open
#702 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PowerShell
Stars
11.2k
Forks
9.1k
Avg merge
2d 7h
Merged PRs (30d)
14

Description

Hi,
I am tring to execute the below query and getting error as Access denied,
Can you please help me to fix this error.

DECLARE @PATH NVARCHAR(4000) = 'D:\SAP_Download\TPM_MATERIAL_MASTER_20191209_101848.txt'

DECLARE @CMDSQL NVARCHAR(4000) = 'Cmd.exe /S /C " "D:\SAP_Download\BatchFile.bat" "D:\SAP_Download\TPM_MATERIAL_MASTER_20191209_101848.txt""'

Exec master..xp_cmdshell @CMDSQL

In .bat file the below code
@ECHO OFF
SET "fileName=%1"

"C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\python.exe" "D:\SAP_Download\convertFileFormat.py" %fileName%

And in python file,
import time
import sys
import codecs
import os
myfile = codecs.open(sys.argv[1], encoding='utf-8')
marylines = myfile.readlines()
myfile1 = codecs.open(sys.argv[1], 'w', encoding='utf-16')
for line in marylines:
myfile1.write(line)
myfile1.close()
myfile.close()

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the xp_cmdshell invocation and BatchFile.bat, then inspect convertFileFormat.py and the Python executable path. Reproduce the command under the SQL Server service account and determine which step returns Access denied; no repository test or acceptance criterion is provided.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.