473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

locking an SQL Server DB with .NET

Hi,

My VB.NET-application has to do some actions on a SQL Server Database, but
during these actions the DataBase may not be used by any other application.
the total time of the lock could be up to 15 minutes. How can I perform
something like a lock, who denies other users/applications to access the
Database, and after a while grant themagain permission.

Thanks,

Pieter
Jul 21 '05 #1
5 1406
Pieter:

Transact SQL has a number of locking hints that can be used in queries to
provide the appropriate level of database locking. I would recommend
browsing SQL Server Books On Line for more information on locking hints, as
well as other ways to lock a database.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:#Q**************@TK2MSFTNGP15.phx.gbl...
Hi,

My VB.NET-application has to do some actions on a SQL Server Database, but
during these actions the DataBase may not be used by any other application.
the total time of the lock could be up to 15 minutes. How can I perform
something like a lock, who denies other users/applications to access the
Database, and after a while grant themagain permission.

Thanks,

Pieter

Jul 21 '05 #2
See "ALTER DATABASE" in BOL. You can use this statement to set the database
status in SINGLE_USER, do your stuff and set it back to MULTI_USER.

Example:

use northwind
go

alter database northwind
set SINGLE_USER with ROLLBACK IMMEDIATE
go

-- do your stuff here
....
go

alter database northwind
set MULTI_USER
go
AMB

"DraguVaso" wrote:
Hi,

My VB.NET-application has to do some actions on a SQL Server Database, but
during these actions the DataBase may not be used by any other application.
the total time of the lock could be up to 15 minutes. How can I perform
something like a lock, who denies other users/applications to access the
Database, and after a while grant themagain permission.

Thanks,

Pieter

Jul 21 '05 #3
Thanks both.
Isn't it a bit dangerous to do things like this? Otherwise: what if i workd
with a different kind of login/username, and put the rights of the other
users to read-only (db_datareader)?

"Alejandro Mesa" <Al***********@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
See "ALTER DATABASE" in BOL. You can use this statement to set the database status in SINGLE_USER, do your stuff and set it back to MULTI_USER.

Example:

use northwind
go

alter database northwind
set SINGLE_USER with ROLLBACK IMMEDIATE
go

-- do your stuff here
...
go

alter database northwind
set MULTI_USER
go
AMB

"DraguVaso" wrote:
Hi,

My VB.NET-application has to do some actions on a SQL Server Database, but during these actions the DataBase may not be used by any other application. the total time of the lock could be up to 15 minutes. How can I perform
something like a lock, who denies other users/applications to access the
Database, and after a while grant themagain permission.

Thanks,

Pieter

Jul 21 '05 #4
what is it that you are doing that you want to write to the db but you are
willing to allow others to read from it?

And why on earth does it take 15 minutes?

Are you pulling data out for a data warehouse?

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:Oo**************@TK2MSFTNGP14.phx.gbl...
Thanks both.
Isn't it a bit dangerous to do things like this? Otherwise: what if i
workd
with a different kind of login/username, and put the rights of the other
users to read-only (db_datareader)?

"Alejandro Mesa" <Al***********@discussions.microsoft.com> wrote in
message
news:94**********************************@microsof t.com...
See "ALTER DATABASE" in BOL. You can use this statement to set the

database
status in SINGLE_USER, do your stuff and set it back to MULTI_USER.

Example:

use northwind
go

alter database northwind
set SINGLE_USER with ROLLBACK IMMEDIATE
go

-- do your stuff here
...
go

alter database northwind
set MULTI_USER
go
AMB

"DraguVaso" wrote:
> Hi,
>
> My VB.NET-application has to do some actions on a SQL Server Database, but > during these actions the DataBase may not be used by any other application. > the total time of the lock could be up to 15 minutes. How can I perform
> something like a lock, who denies other users/applications to access
> the
> Database, and after a while grant themagain permission.
>
> Thanks,
>
> Pieter
>
>
>


Jul 21 '05 #5
Hehe good question :-)
Well: I need to write some sort of replication between different SQL
Servers, and the replication has some very specific property's:
- The SQL Servers doesn't have a direct connection: it's between different
palmtree-plantations in africa, and the only communication they have is once
a week to send as-small-ass-possible files with some kind of radio :-)
- so during the replication/synchronization people shouldn't be allowed to
make any other changes in the databases
- the 15 minutes: they are just slow over there to follow the whole
procedure...
"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> wrote in message
news:Cb********************@comcast.com...
what is it that you are doing that you want to write to the db but you are
willing to allow others to read from it?

And why on earth does it take 15 minutes?

Are you pulling data out for a data warehouse?

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:Oo**************@TK2MSFTNGP14.phx.gbl...
Thanks both.
Isn't it a bit dangerous to do things like this? Otherwise: what if i
workd
with a different kind of login/username, and put the rights of the other
users to read-only (db_datareader)?

"Alejandro Mesa" <Al***********@discussions.microsoft.com> wrote in
message
news:94**********************************@microsof t.com...
See "ALTER DATABASE" in BOL. You can use this statement to set the

database
status in SINGLE_USER, do your stuff and set it back to MULTI_USER.

Example:

use northwind
go

alter database northwind
set SINGLE_USER with ROLLBACK IMMEDIATE
go

-- do your stuff here
...
go

alter database northwind
set MULTI_USER
go
AMB

"DraguVaso" wrote:

> Hi,
>
> My VB.NET-application has to do some actions on a SQL Server Database,
but
> during these actions the DataBase may not be used by any other

application.
> the total time of the lock could be up to 15 minutes. How can I

perform > something like a lock, who denies other users/applications to access
> the
> Database, and after a while grant themagain permission.
>
> Thanks,
>
> Pieter
>
>
>



Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Arska | last post by:
Hi Is it possible to force row level locking in one or more tables in some database. We have some problems when SQL Server decides to choose page- or table-level locking. We are using SQL...
12
by: Puvendran | last post by:
Hi, We have encountered deadlock on a table which is used to generate sequential numbers for different categories eg typical entries Category Value TRADE_NO ...
0
by: Prashant Thakwani | last post by:
We are having application running on SQL Server 6.5. Now the management decided to upgrade that application to SQL server 2000 becasue of the Locking problems in SQL Server 6.5 . i Upgrade that on...
3
by: Ryan | last post by:
I have a problem with record locking / blocking within an application. The app is quite straight forward. Written in Delphi 5 using BDE to access a SQL 7 database (Win2K server). Every so often...
9
by: john smile | last post by:
Hi All, I want to lock 2 tables on 2 servers using TABLOCKX hint. These tables function as semaphores in my application. It means when the tables are locked then other users will not be able to...
2
by: Randall Sell | last post by:
Hello all, Somewhere on these newsgroups I recall reading that SQL Server 6 and prior (when they were married with Sybase) used page locking and not row level locking. Hence you could be locking...
16
by: Nid | last post by:
How do I do row-level locking on SQL Server? Thanks, Nid
3
by: Wolfgang Bachmann | last post by:
We migrated a database from Version 5.1 to 8.1 and are experiencing massive locking problems. We migrated in the following steps: 0) Server 5.2, Clients 5.2: everithing was fine 1) Server 5.2,...
15
by: z. f. | last post by:
Hi, i have an ASP.NET project that is using a (Class Library Project) VB.NET DLL. for some reason after running some pages on the web server, and trying to compile the Class Library DLL, it...
7
by: Shak | last post by:
Hi all, I'm trying to write a thread-safe async method to send a message of the form (type)(contents). My model is as follows: private void SendMessage(int type, string message) { //lets...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.