kishore

kishore

  • 1.6k
  • 116
  • 5k

find the running exec master..xp_cmdshell bcp select when cancel button click in c# windows application

Jul 2 2012 1:12 AM
I had one issue in C# windows application.


Here i am working with C# windows applications.


My question like, i have one form with two buttons submit & cancel 


In button click i am staring one thread.


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". 


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.


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'''


exec master..xp_cmdshell ''bcp Databasename..' + @database table+ ' out "' + @serverfolder+ 'temp_' + @user specified file name + '.csv" -c -t, -T -Slocalhost'''


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"'''


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" & "user specified file name.csv"from the folder and updating the databse.


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.


if i close the application even bcp process still running.


How to close the bcp.exe alive session when cancel button click.


kindly let me know the solution.

Thanks & Regards
KishoreD