[dba-SQLServer]Determine which database a sproc is being calledfrom

Stoker, Kenneth E Kenneth.Stoker at pnl.gov
Fri Feb 13 18:33:59 CST 2004


That is what I was looking for.  That is better than the method I just
came up with and sent back to the list.  I had tried db_name and didn't
work, obviously because I didn't use db_name().  

The reason I needed this is because I built a couple of sprocs that
add/remove accounts and add memberships to SQL roles based on
information in a couple tables.  Since my current production database
for this only had one database on it, I didn't do any checking to see if
the accounts being removed belonged to other databases.  Now that we
have put this in production, other systems have expressed possible
interest, but only if the sprocs would review all databases on the
system and only remove accounts from the server that didn't belong to
any other databases.  So, with the current database name, I can now go
through the list of database users, excluding those from the current
database, and remove only those that don't have access to other
databases and no longer exist in the source table specifying who should
have access.  The source table is populated based on role structure
within the Active Directory of our network.

Anyway, thanks very much Billy.  Cuts the number of lines of code down.
Always like that.

Ken Stoker
Technology Commercialization
Information Systems Administrator
PH: (509) 375-3758
FAX: (509) 375-6731
E-mail:  Kenneth.Stoker at pnl.gov 


-----Original Message-----
From: Billy Pang [mailto:tuxedo_man at hotmail.com] 
Sent: Friday, February 13, 2004 4:23 PM
To: dba-sqlserver at databaseadvisors.com
Subject: RE: [dba-SQLServer]Determine which database a sproc is being
calledfrom


well, there's db_name() but that only gets the current database you are 
in...


>From: "Stoker, Kenneth E" <Kenneth.Stoker at pnl.gov>
>Reply-To: dba-sqlserver at databaseadvisors.com
>To: dba-SQLServer at databaseadvisors.com
>Subject: [dba-SQLServer]Determine which database a sproc is being 
>called
>from
>Date: Fri, 13 Feb 2004 15:04:43 -0800
>
>Is there a way for a sproc to determine which database it resides in 
>when called?  I would like to make a sproc I am build generic enough so

>that it can be implemented in any database within a server instance.
>
>Thanks for any help.
>
>Ken Stoker
>Technology Commercialization
>Information Systems Administrator
>PH: (509) 375-3758
>FAX: (509) 375-6731
>E-mail:  Kenneth.Stoker at pnl.gov
>
>_______________________________________________
>dba-SQLServer mailing list
>dba-SQLServer at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
>http://www.databaseadvisors.com
>

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online  
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com



More information about the dba-SQLServer mailing list