473,480 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1408
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
5436
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
9538
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
437
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
5107
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
5049
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
6860
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
8892
by: Nid | last post by:
How do I do row-level locking on SQL Server? Thanks, Nid
3
2748
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
6131
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
2837
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
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6908
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
7044
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
6929
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4779
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
181
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.