Pergunta

I have a project where I am uploading a lot of data in the form of text files to SQLServer. There is a python script which calls the BCP command iteratively using the function SQLUpload. The input into this function is:

SQLUpload(prefix,suffix,uploadingDirectory,formatFileDirectory,server,tableName,
                                                     userName,passWord)

And the line which uses the subprocess module to iteratively call the BCP command is as follows (please comment if you need more code than this):

batchCommand = 'BCP ' + tableName + ' in ' + os.path.join(directory,dataFile) + ' -U ' \
                       + userName + ' -P ' + passWord + ' -S ' + server \
                       + ' -f ' + formatFileDirectory
err = subprocess.call(batchCommand,stderr=subprocess.PIPE,shell=True)

The error is as below:

Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
  SQLUpload(prefix,suffix,uploadingDirectory,formatFileDirectory,server,tableName,userName,passWord)
  File "H:\Engineering\MWDownload\HDC\Scriptfile\SQLUploader - Local.py", line 66, in SQLUpload
    err = subprocess.call(batchCommand,stderr=subprocess.PIPE,shell=True)
  File "C:\Python33\lib\subprocess.py", line 523, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\Python33\lib\subprocess.py", line 789, in __init__
    errread, errwrite) = self._get_handles(stdin, stdout, stderr)
  File "C:\Python33\lib\subprocess.py", line 1006, in _get_handles
    c2pwrite = self._make_inheritable(c2pwrite)
  File "C:\Python33\lib\subprocess.py", line 1038, in _make_inheritable
    _winapi.DUPLICATE_SAME_ACCESS)
OSError: [WinError 6] The handle is invalid

Does this error mean that I do not have permission with my current username and password? Or does it mean something else?

Thanks in advance.

Foi útil?

Solução

For some reason a restart worked.

I ran the script again. It picked up from where it left from and then worked.

Bizarre. Here is some information on Windows Handles

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top