Solved

Lock table before insert

Posted on 2010-11-28
19
1,498 Views
Last Modified: 2013-11-11
hi all ,,,
i am working on funcation to insert some data in a table using Linq to sql .. and i am facing a problem where i dont know how to lock a table untill i finish inserting .. i dont want any other users to be able to inster into it but i want them to be able to update it and select from it.
0
Comment
Question by:VCyrus
  • 7
  • 5
  • 2
  • +1
19 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 34225271
>>i dont want any other users to be able to inster into it but i want them to be able to update it and select from it.

To the best of my knowledge - impossible.
0
 
LVL 1

Author Comment

by:VCyrus
ID: 34228236
hi ,,,
if that is impossible , can i just lock it when i am inserting and block any other users from doing any other operation ???
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34228277
In theory yes.  It can depend on the database and drivers you are coding with.
0
 
LVL 1

Author Comment

by:VCyrus
ID: 34228299
and the way to do this is ????

i am currenty working with C# , LINQ2SQL and SQLserver in windows forms application.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34228517
I know that some SQL drivers in .NET don't offer as many options as in the unmanaged world.

Does the following link help you - it is about locking in SQL Server.
http://www.sqlteam.com/article/introduction-to-locking-in-sql-server
0
 
LVL 1

Author Comment

by:VCyrus
ID: 34228972
Sorry ..
no, this is not what i am looking
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34228984
If the option you want isn't available then it isn't available and you can't do what you wanted.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 1

Author Comment

by:VCyrus
ID: 34229417
the link you have provided is talking about SQL statements ...
i said that i am looking for linq to sql solution ..
how can i - using linq to sql  - do single insert for one user and block others who want to insert at the same time .
 
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34229492
>>the link you have provided is talking about SQL statements ...

Yes, it describes how to lock a table under different scenarios, such as when you are inserting data.  If it isn't supported by the driver you use then one is stuck.

From an earlier comment:
I know that some SQL drivers in .NET don't offer as many options as in the unmanaged world.
0
 
LVL 1

Author Comment

by:VCyrus
ID: 34236815
i am still looking for other solution under linq
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 34388595
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34626185
The original question was answered.  No is an acceptable answer.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34635690
coment #34225271 answers the original question.  (At least I, and no other expert has offered a different opinion, think it is impossible)
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 34675701
@AndyAinscow

Do you think there is no use of my comment in ID: 34388595 ???

Since I am not going to get points, but it should clear to me for knowledge.
0
 

Expert Comment

by:thermoduric
ID: 34709716
I am starting the auto-close procedure in this question. After moderator review, it would appear valid solutions were provided.

- thermoduric -
EE Community Support Moderator
http://www.experts-exchange.com/Q_26750827.html

0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now