Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Exclusive use

Author  Topic 

dragonsbb1616
Starting Member

6 Posts

Posted - 2011-05-25 : 12:33:18
I am using SQL 2005 Express.....I would like to know if I can Lock a Table, Database or Record via the login I have in my .Net connection string code?

Nothing would be performed physically from within SQL Server Management program. It would have to be done as part of my connection string and login object.

In my old database (Access 2000) you could not exclusively lock a TABLE, only the Entire Database.

I am looking to understand the Exclusive concepts in SQL 2005.
Any help would be greatly appreciated.

Thank you.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-25 : 12:50:14
You can't do it at the connection string/login object level. It has to be done at the query level.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dragonsbb1616
Starting Member

6 Posts

Posted - 2011-05-25 : 13:14:44
So just so that I understand correctly. I would have something part of my SQL statement stating the exclusive locking?
i.e. SELECT * FROM MYTABLENAME WHERE X=0

I am know SQL statements....but I dont know how to integrate your comment into an SQL statement. Could you give a simple example of exclusive locking a table, an entire database, and a individual record? or know of a website that has that example. I did a google search for that and couldnt find much.
Go to Top of Page

dragonsbb1616
Starting Member

6 Posts

Posted - 2011-05-25 : 13:18:31
In Access/VB6 it was part of your Connection string and Login object, not the actual Query statement. Trying to shift my mentality.
Go to Top of Page

dragonsbb1616
Starting Member

6 Posts

Posted - 2011-05-25 : 13:20:32
Ideally, Id like to be able to Exclusively lock a Table....Records and Database locking would be a bonus if SQL2005 can even do that too.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-25 : 13:55:37
You can't lock a database. Take a look at "table hint" topic in BOL for examples and the different types. You'd use TABLOCKX to exclusively lock a table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dragonsbb1616
Starting Member

6 Posts

Posted - 2011-05-25 : 13:56:35
@tkizer Could you confirm that this link is what your talking about when referring to Locking within the Query?

http://blog.sqlauthority.com/2007/04/27/sql-server-2005-locking-hints-and-examples/
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-25 : 14:44:32
Well that's not the link, but it does talk about this subject. Don't you have BOL (Books Online) installed so you can see the topic I'm referring to?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-25 : 14:45:25
If you don't have BOL installed (which seems unlikely), here's the link to it from MSDN: http://msdn.microsoft.com/en-us/library/ms187373(v=sql.90).aspx

You'll need to copy/paste the link rather than clicking on it as Snitz messes up the links.


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dragonsbb1616
Starting Member

6 Posts

Posted - 2011-05-25 : 15:59:47
Thank you for all help in narrowing my search. That was spot on.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-25 : 16:09:42
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -