Saturday, April 30, 2016

Netbeans Issues with tableChanged event for JTable

I've struggled most of the day today to get the tableChanged() event to fire for a JTable I created to link to a database table, and wanted to share my solution.

As the linked video shows, after creating a custom listener that implements TableModelListener, and adding the listener to the table model object, the listener refused to fire.

Long story short, the answer turned out to be that I had failed to provide a name for the Default elements binding object. (See screenshot immediately below)

Here is a video of me demonstrating this phenomenon more thoroughly. I hope you find it instructive.

Wednesday, April 27, 2016

SQL Server: T-SQL JOB to kill sessions with long-running transactions

We have a situation in a build/test server in which the application server (jboss, in this case) is unceremoniously killed by the build process.

This is leaving us with transactions that are not committed, nor are they rolled back. I like to call these zombies. SQL Server thinks they're just happily executing.

Because SQL Server has no server side lock, transaction, or query timeout, I developed this job to simulate a 10 minute transaction timeout.

It's not sophisticated, but it will give you a good starting point in case you should have to create your own .

if not exists (select * from sys.schemas where name = 'LOGSCHEMA')

if exists (select * from sys.tables where name = '#OLD_SPIDS')
 /* NOTE: In the following, I fully qualified the Kill_Long_Running_tran_log table as dbname.schema.tablename. DB_NAME will need to be changed */
if not exists (select * from sys.tables where name = 'Kill_Long_Running_tran_Log')
EXEC ('CREATE TABLE [/*change db_name */DB_NAME].[LOGSCHEMA].[Kill_Long_Running_tran_Log] (msg_timestamp datetime2(7), msg varchar(256))')

DECLARE @session_to_kill int = 0
DECLARE @kill_session_statement nvarchar(max)

select dtst.session_id
, dtst.transaction_id
, dtat.transaction_begin_time
from sys.dm_tran_session_transactions dtst
join sys.dm_tran_active_transactions dtat
on dtst.transaction_id = dtat.transaction_id
where dtat.transaction_begin_time < DATEADD(MINUTE,-10,current_timestamp)

select @session_to_kill = session_id
where transaction_begin_time = (select min(transaction_begin_time) from #OLD_SPIDS )

select @kill_session_statement = 'kill ' + cast(@session_to_kill as varchar(10))

if (@session_to_kill != 0)
insert into [LOGSCHEMA].[Kill_Long_Running_tran_Log]
values (current_timestamp, @kill_session_statement)
exec (@kill_session_statement)


Scripting out existing database mail configuration

SQL Server Central Artical on Scripting out Existing database mail configuration I wanted to save this here so I can easily find it. Sorry ...