title: Terminate the running exec master..xp_cmdshell bcp select session when cancel button click in c# windows application
body: <p>I had one issue in C# windows application.</p>
  
  <p>Here i am working with C# windows applications.</p>
  
  <p>My question like, i have one form with two buttons submit &amp; cancel </p>
  
  <p>In button click i am staring one thread.</p>
  
  <p>The thread contains one stored procedure having the below code part, here it will select bulk information from the .csv file and loading in to the server project folder with the temp_"user specified file name.csv". </p>
  
  <p>when process compleats we are copieng temp_"user specified file name.csv" information to the "user specified file name.csv" and finally we are removing the temp_"user specified file name.csv" from the server folder. its working fine.</p>
  
  <p>exec master..xp_cmdshell ''bcp "select ''''Column1'''',''''Column2'''',''''Column3'''',''''Column4'''',''''Column4'''',''''Column5'''',''''Column6'''',''''Column7'''',''''Column8''''" queryout "' + @Parent_Folder + @Transformed_Tbl + '.csv" -c -t, -T -Slocalhost'''</p>
  
  <p>exec master..xp_cmdshell ''bcp Databasename..' + @database table+ ' out "' + @serverfolder+ 'temp_' + @user specified file name + '.csv" -c -t, -T -Slocalhost'''</p>
  
  <p>exec master..xp_cmdshell ''copy /b "' + @serverfolder+ @user specified file name + '.csv" + "' + @serverfolder+ 'temp_' + @user specified file name + '.csv" "' + @serverfolder + @user specified file name+ '.csv"'''</p>
  
  <p>Its running perfectly,But at the time of process running when i hit the cancel button,here i am aborting the running thread and deleting the "temp_user specified file name.csv" &amp; "user specified file name.csv"from the folder and updating the databse.</p>
  
  <p>Its aborting and closing all the sql sessions and updating the database but its not deleting the file "temp_user specified file name.csv",why because in the server folder still bcp process still running and sql server having an one alive session.</p>
  
  <p>if i close the application even bcp process still running.</p>
  
  <p>How to close the bcp.exe session when cancel button click.</p>
  
  <p>kindly let me know the solution an urgent basis..</p>