c# - Create a 'Licensing' feature with SQL-Server -
i want implement following interface on 2-tier application ms sql-server 2008r2 (i.e. no app server in between)
interface ilicense { void acquire(string license); void release(string license); }
however, want release license if application killed or bombs out without calling release
method. want avoid using timer refreshes license every minute or so.
so thought: use dedicated sqlconnection
sp_getapplock
, sp_releaseapplock
sp because that's seemed made for. found out sp work within transaction, need keep transaction open time (i.e. while application running). anyway, works way. application starts, opens connection, starts transaction, , locks license. when application terminates, connection closed, rolled , license released. super. whenever running app needs switch licenses (e.g. module), calls release
on old license , acquire
on new one. cool.
now question(s):
- is acceptable have open (uncommitted) transaction open on separate connection long time?
- are there better possibilities implement such 'lock' mechanism? problem license shall released if application terminates unexpectedly. thought of sort of 'logout' trigger, not exist in sql-server 2008r2
i no means sql or db guru of members of site setup brings few concerns or things consider.
this limit number of concurrent users application have in 2-tier architecture. in 3 tier approach app server manage , pool these connections/transactions lose ability use stored procs implement licensing mechanism, believe.
with transaction being open indeterminate period of time worry possibility of tempdb growing big or exceeding space allocated it. don't know going on in app , if there else going on in transaction, guess no thought mention it.
i hope not getting sql versions mixed here transaction wraparound cause db shutdown.
this limits app data in transaction has lock on won't released until commot or rollback.
there must more elegant way implement licensing model doesn't rely on leaving transaction open life of app or app module. if have 2 tier app implies client has kind of connectivity maybe generate kind of unique id client , either add call home method or if set on there being instantaneous verification everytime client performs action queries db have check see if client licensed etc.
lastly, in of sql teachings have received other db guys know there stuff kind of setup (long running open transaction) never recommended unless there specific need not solved otherwise.
Comments
Post a Comment