SQL Server: How to unlock a table / row? - sql

We recently updated our WPF application to perform its data synchronisation (using sync framework) within a single transaction against our SQL Server 2008 database.
Almost straight away this has somehow led to a row being locked in of of the tables
preventing all other users from syncing.
The thing is that the lock does not seem to be lifting and we are not sure how to resolve the situation.
Any feedback appreciated

The only way to release a row lock is to commit or rollback the transaction in which the lock was taken.

Related

Is there any way to rollback transactions in SQL Server?

Yesterday I wrote some code module, that wrote wrong data in almost 400 existing records in important database on SQL Server 2008. I didn't make backup of this database (my mistake). So the question is how do I rollback these 400 transactions? Is there any way to do this? Thanks.
You can't rollback, but if the database is in full recovery model, then you can restore to another servar with stopat, and recover the deleted rows from there.
You can roll back a transaction as long as you haven't committed it.
But if you ran it yesterday, chances are very high you did commit - and then there's no way back.
So you're options are to
either restore a backup (and next time remember to take one before such an operation!)
manually "undo" those 400 transactions

Database Transaction Notifying of Changes When no Changes Made when using Database Link

I use sqldeveloper (but this problem has also been duplicated on TOAD, so I don't think it's specifically related to sqldeveloper). The basic problem is after I run a complex SELECT query that uses a database link through sqldeleloper, it will notify that I have changes that need to be rolled back or committed when I go to close my session. The weird part is that I was only running a SELECT query and there are no changes to COMMIT. Can someone explain this behavior to me?
An implicit transaction occurs when selecting over a dblink.
When Oracle performs a distributed SQL statement Oracle reserves an
entry in the rollback segment area for the two-phase commit
processing. This entry is held until the SQL statement is committed
even if the SQL statement is a query
More on this here. I'll try to dig up an Oracle link if I can.
More from the horses mouth:)
Two-Phase Commit Mechanism
A database must guarantee that all statements in a transaction,
distributed or non-distributed, either commit or roll back as a unit.
The effects of an ongoing transaction should be invisible to all other
transactions at all nodes; this transparency should be true for
transactions that include any type of operation, including queries,
updates, or remote procedure calls.
More from Oracle's Distributed Database Concepts guide

SQL compact synchronization

I am synchronizing sql server and sqlCE database. once the synchronization is over, I need to delete the Sync Completed records from SqlCE database.(not from server). so that I can keep the db size low. When I delete the completed records and their trackings from SqlCE db, still there are "UploadChangesTotal" showing. How do I handle this situation?
you can intercept the upload on the ChangesSelected event and remove the delete rows from the change dataset so they dont get propagated to the server.
see: MANIPULATING THE CHANGE DATASET IN SYNC FX

roll back SQL query executed by mistake

I think the question says it all,
the following update query has been executed - by mistake - in SQL Server management studio
update kms_students set student_campus='4' where student_campus='KL'
The effected rows are more than 1000, and i can't identify it since that table is already have the student_campus='4' for many previous rows.
Is it possible to roll back?
I believe ApexSQL should do the trick.
ApexSQL works by analyzing the physical transaction log which basically has all the necessary info to restore specific transactions and data, but MS doesn't provide an out-of-box tool to manage it, other than restoring a backup and then manually restoring the transaction log up to a particular date using RESTORE LOGS
Backup. Most Hosting companies keep one, try calling everyone asap.
Your own backups. Even if they're old they will be helpful.
Keep lots of Backups and NEVER try out queries on production environment. NEVER.(Bet you learned that, right?)
To make it a bit easier, you can try putting the backup DB online and execute some PHP/Python/whatever so as to compare each record from the Backup and change the current database fom '4' to 'KL' where needed.
May not be perfect, but can help you avoid a few days of work.

How to recover deleted rows from SQL server table?

I accidentaly ran a DELETE command against a table with a wrong WHERE
clause.
I am using SQL Server 2005.
Is there a way that could help me recover the lost data?
It is possible using Apex Recovery Tool,i have successfully recovered my table rows which i accidentally deleted
if you download the trial version it will recover only 10th row
check here http://www.apexsql.com/sql_tools_log.aspx
You have Full data + Transaction log backups, right? You can restore to another Database from backups and then sync the deleted rows back. Lots of work though...
(Have you looked at Redgate's SQL Log Rescue? Update: it's SQL Server 2000 only)
There is Log Explorer
I think thats impossible, sorry.
Thats why whenever running a delete or update you should always use BEGIN TRANSACTION, then COMMIT if successful or ROLLBACK if not.
What is gone is gone. The only protection I know of is regular backup.