Select to view content in your preferred language

Batch Job or Automated Code for finding and killing SDE locks on a particular table.

851
1
04-15-2010 12:51 AM
MuzammilAK
Deactivated User
Dear All,

I have a batch job in place which truncates the existing table and loads the new data (using sdeimport) . Of late, i have been getting errors like 'table has been locked', while data loading.

So, I have decided to modify the job.

Firstly, I need to find the locks on my table. And then kill the process. I have figured out how to do it manually as shown below. But i need to automate it. Please help.

1. to find out the registration_id for that table
select registration_id,table_name,owner from sde.table_registry where table_name='myTable'
2. match for above registration_id in below results' sde_id
sdemon -o info -I locks  --- to find out table lock information
3. sdemon -o kill -t sde_id

How to automate the same to schedule it as a scheduled job?

It need not be a batch program. I can also have .net program too. Please help.

Thank you.

Regards
Muzammil
0 Kudos
1 Reply
MarielaDel_Rio
Regular Contributor
I think there may be  two ways to do this on .NET
1)
You still have to create a batch program. In fact maybe two of them, one for the info and one for the kill (that you will create on the fly)
-Create a .NET program
-Execute your SQL command to get the Table ID
-run the sdemon -o info command using the bat file
you have to use the System.Diagnostics.Process
you also need to use process startinfo and a StreamReader to get the result (the process IDs with Tables)
read each line of the result and find the the processid until for the TableID you have, when you find it, compose your command. I don't think you can execute SDE commands directly with the Diagnostics Process, so you will have to create a batch file with the command and run it when is created.

2) Use a shell execute command from the program.
run your shell command and send the results to a file (>file.txt")

I have not tried it to see if it will run SDE commands, but I don't see why not. I have not used this in C#, just VB.net, so I don't know the libraries you need to include.

read your file, and get the info you need for your kill command
compose your kill command
run another shell execute statement within the program.


You can save the executable program and put it in the scheduler.
0 Kudos