Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1051
  • Last Modified:

SQL Stored Procedure --> Getting the server to send its MAC address to a client (trigger)

Here's the problem......

I have a MS Access Application that connects to a SQL database on a remote server. What has to happen is that when the connection is made to the the server, the server needs to send back its MAC address to the application so I can compare it to the MAC address I have stored in a local MS access table.

Is there some kind of trigger / SP that will do this for me?

Thanks
0
b_o_b
Asked:
b_o_b
  • 8
  • 8
  • 3
1 Solution
 
mastooCommented:
You'd have to probably run a proc to retrieve sysprocesses.net_address where spid = @@SPID from the master database.  I believe that is the client MAC address.
0
 
jdlambert1Commented:
There is no T-SQL function for this, and the difficulty is compounded by the fact than many SQL Servers use mulitple network cards.

Here's a basis for one solution: Create a program that loops through a computer's LANA's, uses each LANA in an NCBASTAT command to get the MAC address for each network card, and then connect to the database and store the values in a configuration table of your own.

Here's some sample code to get started: http://support.microsoft.com/default.aspx?scid=kb;en-us;118623
0
 
jdlambert1Commented:
I happily stand corrected (and better educated!). sysprocessess does indeed store the MAC addresses. Just be careful about one server having more than one...

Thanks, mastoo!
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
jdlambert1Commented:
As simple as:

SELECT Distinct net_address
FROM master.dbo.sysprocesses
WHERE net_address <> ''

I didn't know you could do that!  I love EE!
0
 
ShogunWadeCommented:
ah.   one slight flaw,     "the server needs to send back its MAC address to the application "   of course net_address in sysprocesses is the client macaddress.
0
 
jdlambert1Commented:
I tested the query using FROM master.dbo.sysprocesses against a couple of my systems, and it only returned the server's MAC addresses, so using the master table seems to be the key.
0
 
jdlambert1Commented:
Okay, I'm still ignorant. sysprocesses only exists in master, so how come I'm not getting client addresses?
0
 
ShogunWadeCommented:
BOL:

"net_address nchar(12) Assigned unique identifier for the network interface card on each user's workstation. When the user logs in, this identifier is inserted in the net_address column. "
0
 
ShogunWadeCommented:
jd,  i dont suppose you were lookin at the process info for any sql agent tasks ?
0
 
ShogunWadeCommented:
Try this:





CREATE PROCEDURE usp_ServerMacs AS

create table #t (a varchar(500))
insert #t
exec xp_cmdshell 'ipconfig /all'
select LTRIM(RTRIM(SUBSTRING(a,CHARINDEX(':',a)+1,200))) MacAddress from #t where a like '%physical address%'
0
 
jdlambert1Commented:
I'm not only ignorant, I'm stupid. I ran it on development systems, not production boxes. The only connections were from the tools and services running on the dev systems.  Duh.

@@spid doesn't seem to help, as it "Returns the server process identifier (ID) of the current user process."

The command shell you posted worked for me, Shogun. I'm gonna bookmark this Q in case I ever need that. :)
0
 
ShogunWadeCommented:
no worries.    one slight thing is that the format returned has -'s in which is a a touch differnet than the net_address in sysprocesses.   but of course its trivial to remove those.   but I think it should return all macs.  cant really test that here though cos I've only got a single card :(
0
 
jdlambert1Commented:
I tested it with multiple cards and it works perfectly!

You want us to take up a collection to get you a second card, Shogun?
0
 
ShogunWadeCommented:
Na, Ive got no free slots in this 8088 machine ;)
0
 
mastooCommented:
Ah, as you all observed I read the original question too quickly and thought the question was looking for the client MAC.  I like the shell approach above.  I think you ccould also use the sysprocesses method but just go after one of the sqle entries - since sqle is running on your sql server box (assuming you have sqle running).
0
 
ShogunWadeCommented:
only snag there is that the net_address is supressed for system processes, otherwise you could have easily done this by taking the net_address of SPID 1
0
 
mastooCommented:
I forgot sometimes people have trouble reading my mind.  By sqle I meant whatever account you have Sql Agent running under, assuming it is not just using the local system account.  It runs on the same box and shows up with the server's mac.  But the shell method is probably better as it doesn't rely on undocumented behavior such as counting on Sql Server storing the MAC in this column.
0
 
ShogunWadeCommented:
I think my solution gives what was asked
0
 
jdlambert1Commented:
All points should go to Shogun, IMHO.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 8
  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now