473,386 Members | 1,795 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.

How to Identify Connection

NeoPa
32,556 Expert Mod 16PB
I have multiple users using an Access front end plugged into a SQL Server back end.

I want something that identifies the user's session to SQL server.

I've tried @@SPID and found that there can be multiple values when connecting from the same session of Access.

Equally, login and user names/IDs are not reliable as it's perfectly possible to have more than one session of Access going and these need to be treated as separate sessions.

Does anyone have any ideas on how I can identify the current session uniquely?
May 18 '15 #1
13 1956
ck9663
2,878 Expert 2GB
I do it the old fashion way. Generate my own Session ID with the user IP, date and time of connection and a newid(). You can pass it from one page to another then do a check to the server if you want the connection to proceed ie. force timeout. I only do it for intranet, though. Users might not want to see I'm grabbing their IP, even if we all know it's actually happening every time you open a page :)

Good Luck!!!

~~ CK
May 18 '15 #2
computerfox
276 100+
Would there be a way to generate a random integer for the Access database anytime Access itself loads? Or maybe have a SESSION table and when the user logs in, regardless if it's the same username/password combination, it will create a new record with a randomly generated ID, which would act as the session id?
May 18 '15 #3
computerfox
276 100+
@CK That's actually a pretty creative way of generating a session id, but wouldn't that also cause various session id's if there's a lot of open()/close()?
May 18 '15 #4
Rabbit
12,516 Expert Mod 8TB
You could use the process ID. And on the off chance that the different systems generate the same process ID, combine it with the user name or system name.
May 18 '15 #5
ck9663
2,878 Expert 2GB
You generate the session ID on the home page. It is then pass through from one page to the other. If you need to direct a user to a specific page, just use the home page on the link, generate the session id, then redirect the user to whichever page you want them to, carrying the session ID with them.

The number of session ID you generate depends on the number of user of your page. Every use is a connection, essentially. You may extend it to track which page is mostly accessed by who and what they did on it, or whatever you need to do :)

~~ CK
May 18 '15 #6
NeoPa
32,556 Expert Mod 16PB
Thanks for the ideas guys. My preference is strongly towards an automatic system that I don't have to code in by changing things in my project. If possible, I'd like something pre-existing in SQL Server that means something to anyone else who looks at the project without having to decipher the front end (if that makes sense). Essentially something inbuilt and predefined.

@Rabbit.
You refer to a Process ID. How do I access that?

Am I right to interpret your responses as saying that there is nothing you're aware of that provides this functionality as standard?

Any ideas why the Session ID (@@SPID) returns different values when called by the same remote system? This surprised me frankly.
May 18 '15 #7
ck9663
2,878 Expert 2GB
Could be the way your front-end is retrieving the data from the server. It be opening a session every time.

~~ CK
May 18 '15 #8
Rabbit
12,516 Expert Mod 8TB
You could grab it from the system processes using WMI. But SQL Server logs it for you in a system table. Between these 4 fields, you should be able to find a combination that works for you.
Expand|Select|Wrap|Line Numbers
  1. SELECT session_id, host_name, host_process_id, login_name
  2. FROM sys.dm_exec_sessions
It creates multiple sessions, I presume, so it can run mutliple queries in parallel.

As far as standard functionality, I think this comes down to terminology. This is my understanding of how it works. But I don't have any documentation to back it up so take it with a grain of salt.

As far as SQL Server is concerned, Access is connecting to the database multiple times. So there are multiple connections and multiple sessions. But each of those sessions comes from a certain user and a certain machine. And on those machines, a certain process spawns that connection.

So if you have multiple instances of Access running. Each of those instances of Access gets its own process ID unique to that machine. Each of those instances may connect to SQL Server multiple times. Each instance of Access can be spawned under a different user if they chose to run it under different credentials. So the uniqueness you are looking for could be the combination of login name, process id, and host name. If users are not likely to do so, you can use just process id and login name / host name.
May 18 '15 #9
NeoPa
32,556 Expert Mod 16PB
I can't say that any of that makes a lot of sense to me :-(

That's not to say I don't appreciate your thoughts on the subject by any means. Simply that I can't see why it would need to create multiple sessions with the caller in order to run processes in parallel. Access has a session open with the SQL Server as I force it to artificially by keeping open a form with a recordset (Dynaset) linked to a table from the SQL database. Why Access would need to open multiple sessions is something one could guess at, but there seems nothing to indicate it. I think I need a better understanding of what's going on and why if I'm to make this work properly.

I'll play with the sys.dm_exec_sessions table and post what I find. I'm really looking for a system variable (@@...) for preference, but if I find something usable in here I'll count this a productive exercise.

Regardless of any results I really appreciate all of your time and efforts helping me on this.

PS. Just caught your last update Rabbit. Ta.
May 18 '15 #10
Rabbit
12,516 Expert Mod 8TB
If you were to look at the ports on the local machine, you will see that there are multiple ports on the local machine connecting to the SQL Server. I suspect this is so that SQL Server can send asynchronous results to the correct port. This is conjecture again but suppose there are 2 list boxes on a form. I expect that it would send both queries to populate the list boxes to the server, each query on a different port. Access would listen to each of those ports and wait for the data to return. On the SQL Server side, I suspect it stores the port with the session.
May 19 '15 #11
NeoPa
32,556 Expert Mod 16PB
I'll have to come back to this when I'm a little fresher Rabbit.

What you say makes some sense. How to use that understanding is beyond me at this point in the morning. I'll see what tomorrow brings.

Thanks for all your help :-)
May 19 '15 #12
Rabbit
12,516 Expert Mod 8TB
Sure thing NeoPa.

You may be interested in the following functions available in SQL Server: SUSER_NAME(), HOST_NAME(), HOST_ID(). They return, respectively, the log in name, the client computer name, and the client process id that created the connection.

If they have 2 instances of Access running on their computer, you can identify them with the HOST_ID().
May 19 '15 #13
NeoPa
32,556 Expert Mod 16PB
Rabbit:
You may be interested in the following functions available in SQL Server
You can be sure I am my friend. Hopefully they will allow me to put together a reference which is unique to my Access session. I'll have a play.

Even if not then I can always create a unique reference from the Access end and include that in any communications between the two. That just means I have to update all my queries though, which run into many hundreds unfortunately. If I can find a way for SQL Server to determine who I am without my having to tell it explicitly that will be a big bonus.
May 20 '15 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stephanie | last post by:
I have a problem that I am trying to solve. We have a huge product with a whole lot of ASP and VB code. VB code is all ActiveX dlls which are used by ASP app. When I attempt to add features or fix...
5
by: Fred Zuckerman | last post by:
Hello All, After reading in this group about the preference for connecting to a SQL Server using a connection string instead of a DSN file, I have done just that. BUT, I cannot update my data....
5
by: Ranier Dunno | last post by:
Hi, I'm writing a data layer, and would like all components to have a single place for retrieving a connection to the (SQL Server) database. Currently, I'm treating the connection as somewhat...
7
by: Adam Clauss | last post by:
I am trying to work-around a firewall which limits me to only being able to accept inbound connections on port 80. Unfortunately, I need to two different applications to be able to accept...
10
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through...
19
by: Jaime Stuardo | last post by:
Hi all.. I have created a business logic component that is used from my ASP.NET webform. It works, but connection string to the database is hard coded, as in this method : public DataSet...
6
by: Sharon | last post by:
Hi all. I'm trying first time async socket connection. In all the examples i've seen, the server connection is closed when the message is complete. Is it common to close the connection after...
5
by: mlg1906 | last post by:
I'm developing an intranet site in ASP.NET 2.0 but I can't seem to connect to the DB from within my code. I've created a .vb class that houses a private Connection() that other functions within the...
6
by: Ryan Liu | last post by:
Hi, If I want to uniquely identify a computer. I can read CPU ID or Mac Address. I heard, but is this true: some BIOS can block CPU ID from being read? (In this case, will I get an exception,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.