| Author |
Topic |
|
greaseman
Starting Member
30 Posts |
Posted - 2006-06-08 : 11:32:28
|
| I have an application that is written in Visual Basic, and uses SQL Server. I can connect successfully to SQL Server within the application.My question:I have a group set up on the SQL Server that contains several users that use the application. In my code, I have a line that shows a "User Name" of the user running the program, but does not show the name of the Group. I am using Windows NT authentication. Here is my line of VB code:IsDBO = (UCase$(mconServer.Properties("User Name").Value) = UCase$("dbo")) How might I go about having a similar line of code display the group name instead? The reason I want to do this is obviously to avoid hardcoding the names of users into the code.Any suggestions are appreciated, and I look forward to your replies. Thanks so much!!This forum is best viewed with a computer. Questions asked freely. Confusion happily shared. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-06-08 : 14:56:38
|
| You'll want to post your code in a Visual Basic forum as this information isn't available using T-SQL. You might consider using Environment.UserName if this is VB.NET. There is also Environment.UserDomainName, but that one doesn't provide you with the domain name. I wasn't able to find an environment variable that gave me the domain name in the very little research that I did about a month ago. It turned out that I didn't need the domain name in my code, so I stopped my research.Tara Kizeraka tduggan |
 |
|
|
greaseman
Starting Member
30 Posts |
Posted - 2006-06-08 : 16:17:24
|
| OK.... thanks. Wouldn't you think that if you can get user names easily, you could get group names as easily? But...perhaps I can get the User Name of the group.... Another question..... in my VB code, I see my individual user name showing up, and not the group name. And this is despite my having only the group name set up in the database. Why does that happen?Thanks in advance again!*********************************************************************This forum is best viewed with a computer. Questions asked freely. Confusion happily shared. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-06-08 : 16:21:24
|
| Yes I believe you can get the group name easily, I just didn't figure it out in the limited time that I was considering adding it to my application.Your second question...answer posted in your other thread.Tara Kizeraka tduggan |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-06-08 : 21:02:26
|
from sp_helpuser (extracted)declare @user varchar(20) SELECT usu.name ,case when (usg.uid is null) then 'public' else usg.name end ,lo.loginname ,lo.dbname ,usu.uid ,usu.sid from sysusers usu left outer join (sysmembers mem inner join sysusers usg on mem.groupuid = usg.uid) on usu.uid = mem.memberuid left outer join master.dbo.syslogins lo on usu.sid = lo.sid where (usu.islogin = 1 and usu.isaliased = 0 and usu.hasdbaccess = 1) and (usg.issqlrole = 1 or usg.uid is null) and usu.name=@user --------------------keeping it simple... |
 |
|
|
greaseman
Starting Member
30 Posts |
Posted - 2006-06-09 : 08:36:22
|
| jen,thanks for your reply! However, how might I incorporate something like that into my Visual Basic front-end application, which is where I'd be starting from? My questions are coming from the perspective of a new SQL Server user - I was just assigned the role of administrator of databases and users, etc on my company's newest contract project - no training, no classes and no information. Therefore I most likely am trying to be spoon-fed, so please bear with my questions.Thanks in advance!*********************************************************************This forum is best viewed with a computer. Questions asked freely. Confusion happily shared. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-06-09 : 14:21:10
|
| It would be much better to just make use of the .NET framework than to run a T-SQL statement to get this information. I am sure that the .NET framework easily provides the domain name to your application. To find out how, I'd suggest posting on www.asp.net or some other .NET site.Tara Kizeraka tduggan |
 |
|
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2006-06-09 : 14:36:19
|
| If you are wanting the SQL server group that the user is in, try IS_MEMBER() in TSQL.If you want the Active Directory groups the Windows user is you need to do an LDAP query for the Groups that the given user is in. I don't know the syntax for such, but google should help with that.BTW, VB6 or VB.net?Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights. |
 |
|
|
greaseman
Starting Member
30 Posts |
Posted - 2006-06-12 : 08:26:15
|
| Thanks to all who replied. I got it figured out and am al set. BTW, I was using VB 6 and after a bit of digging, got my VB 6 code working to where I could get the Group infoo I needed.Thanks again.*********************************************************************This forum is best viewed with a computer. Questions asked freely. Confusion happily shared. |
 |
|
|
|