Click here to Skip to main content
15,905,679 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more:
Dear Friends,

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.

SQL
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 session when cancel button click.

kindly let me know the solution an urgent basis..
Posted
Updated 17-Jul-12 20:53pm
v25
Comments
Ganesan Senthilvel 2-Jul-12 6:21am    
SQL format
D-Kishore 13-Jul-12 5:06am    
Dear GanesanSenthilvel,

can you please explain it
D-Kishore 23-Jul-12 1:47am    
Kindly let me know how get the particular bcp process id while using concurrent users.
D-Kishore 13-Jul-12 3:39am    
Dear GanesanSenthilvel,

can you please explain it

1 solution

It is more a suggestion, Try to fetch the processid for your process
C#
using System.Daignostic;
and terminate that process on your cancle button click event.
 
Share this answer
 
Comments
D-Kishore 2-Jul-12 6:48am    
Dear sinhasourabh,

Thanks for your reply,
you mean that i need to fetch process of my applcation process id or stored procedure process id.
i tried fetch my application process id, entire applicaion is closing.
how to get the running bcp process id. Kindly let me know
D-Kishore 2-Jul-12 7:23am    
Dear sinhasourabh,

Thanks for your reply,
you mean that i need to fetch process of my applcation process id or stored procedure process id.
i tried fetch my application process id, entire applicaion is closing.
how to get the running bcp process id. Kindly let me know
Enter your reply below and click the Submit button.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900