473,406 Members | 2,549 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,406 software developers and data experts.

Identifying Connection

Hi All
The problem:!!
I want to create a temp table which is common between different users
so that each user could select his rows and print them without
printing others selection.
All clients use the same connection string.
Is there a way to identify users?
I think it's possible to delete rows of a user when he logs out the
program.
Do I think right?

thanks very much
Hafez
Jul 20 '05 #1
1 1700
Hafez (ha**********@msn.com) writes:
The problem:!!
I want to create a temp table which is common between different users
so that each user could select his rows and print them without
printing others selection.
All clients use the same connection string.
Is there a way to identify users?
I think it's possible to delete rows of a user when he logs out the
program.
Do I think right?


If all you want is a table that goes away with the connection, then
create a temp table like this:

CREATE TABLE #temp (col1 int NOT NULL, ...)

That table is private to the connection, and it goes away when you
disconnect.

There are however situations where this is not feasible. A common technique
in that case is to use @@spid as the key in the table:

CREATE TABLE transient (spid int NOT NULL,
col1 int NOT NULL,
...)
go
DELETE transient WHERE spid = @@spid
INSERT transient(spid, col1, col2, ...)
SELECT @@spid, ...
go
SELECT col1, ...
FROM transient
WHERE spid = @@spid
AND ...

Here there is no automatic cleanup at exit, which is why you must delete
before you can insert anything, so that data that is around from the
previous connection is around.

However, neither this solution is always good. In modern clients you often
work disconnected, and reconnect only when you have something to say
SQL Server. In that case, you may get a different connection. Also, a
popular library like ADO can sometimes open a second connection behind
your back, although you only have one connection object.

To address this you can have some method to get a unique key that is
a negative number (so that you can use @@spid when that is safe.) We
have som 20 tables of this kind in our system, and we get they by
taking checksum(newid()) and the register the key in a special table
which is then cleaned up at night. A simpler approach may be to simply
use a GUID column instead of integer.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

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

Similar topics

5
by: Mark | last post by:
I have an application that uses PHP to access a MySQL table and extract rows which match the user's search entry. Data from the matching rows are loaded into an HTML selection list, and the user...
1
by: David | last post by:
I know that identifying the user IP address with HTTP_SERVER_VARS; is reliant on the browser agent but I have stumpled upon the following code which I have tried to understand but failed! ...
1
by: hokiegal99 | last post by:
This is not really a Python-centric question, however, I am using Python to solve this problem (as of now) so I thought it appropiate to pose the question here. I have some functions that search...
0
by: Joshua Beall | last post by:
Hi All, I've been taking a look at DB Designer 4, and looking through the documentation (http://www.fabforce.net/dbdesigner4/doc/index.html) I am a little unclear on some of their nomenclature:...
7
by: bill.brennum | last post by:
Hi, Have a number of Access Databases that I inherited and want to zip a few of them. My concern is that other active Microsoft Applications may be linking to the database or its tables. Is...
0
by: Jack Kerkhof | last post by:
We have a database that sets a column called MOD_BY = CURRENT_USER to almost all tables on INSERT and UPDATE. But now that the application is n-tier, and uses connection pools, the current_user...
1
by: Jeff | last post by:
Okay, I know there is likely no straght-forward way to get a definitive answer to the question, "why is my page loading so slowly tonight?"; but I'm thinking that there *are* some things we can...
2
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless...
10
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.