.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How to determine if current SQL User is admin or owner?

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :.NET Framework
I wish to determine, from my C# application, if the current user has admin or owner rights to the database they are connected to. I beleive I have all the information required: Servername Database name Windows/Database auth username (If database auth) password (if database auth) I'm trying to find a way that using the smo objects (smo.user), but as of yet I cant quite work it out: - How to get the appropriate user - How to determine if that user is an admin/owner. Any tips would be appreciated. If I have posted to the wrong forum, let me know - I couldnt find one that was obviously more appropriate. Thanks.

View Complete Post

More Related Resource Links

Determine if current user is part of audience


How can I determine if the current user is part of an audience or not?

Searching kept bringing me to this link: http://msdn2.microsoft.com/fr-ca/learning/ms499760.aspx  which is unavailable.

Any help or code is greatly appreciated.



Creating Sites/Lists/List Items under Current User Context in SharePoint By Using SPUserToken

Usually we do this by performing the action under RunWithElevatedPrivileges method and updating the listitem using SPListItem.SystemUpdate() method (see here). but this approach has its own flaws like (RunWithElevatedPrivileges will run under system account, we cannot use SystemUpdate for SPSite,SPWeb,SPList, since it runs under system we will "CreatedBy" by as SystemAccount).

Knowing the event occured in user control in current page




      My web application has user control which uses third party controls called Devexpress controls. The user control is a menu  and is part of the Master page. It is placed there because this needs to be available in all the pages. My user controls raises a even on item clicked. Now, My question is that Is there any way to know that the event has occurred in page_load of the current page in which I am in?

create current user filter in sharepoint designer or wss3

hi, how can i create a current user filter in sharepoint designer?

The name 'User' does not exist in the current context.


Hey guys,

I've got a literal control to display the username of the user logged into our companies intranet system, originally I had a LoginName control but couldn't get strip to remove the domain from the username (as the format is domainname\username) so I'm trying it this way.

    protected void Page_Load(object sender, System.EventArgs e)
        string[] Parts = User.Identity.Name.Split("\\");

        if (Parts.Length == 2)
            loginName.Text = Parts[1];
            loginName.Text = User.Identity.Name;


    protected void Page_Load(object sender, System.EventArgs e)
        string[] Parts = User.Identity.Name.Split("\\");

How to get current logged user name using javascript ?

HelloI am using moss with FBA. I got following javascript to get current user login name. It is displaying curent username properly if user is belong to owner group. But whne I logged with another username who is part of member group(Contribute role), it is not displaying name. Please let me know what I am missing?In following javascript I alerted userId, it is coming in both the case <script type="text/javascript" src="/_layouts/JSAPI/SPAPI_Core.js"></script> <script type="text/javascript" src="/_layouts/JSAPI/SPAPI_Lists.js"></script> <script type="text/javascript" src="/_layouts/JSAPI/SPAPI_UserGroup.js"></script> <script type="text/javascript" src="/_layouts/JSAPI/SPAPI_UserProfile.js"></script> <script language="JavaScript"> var curTitle = null; alert(_spUserId); function getCurrentUserName() { var curUserName = null; var lists = new SPAPI_Lists('') var items = lists.getListItems( 'User Information List', '', '<Query><Where><Eq><FieldRef Name="ID"/><Value Type="Counter">' + _spUserId + '</Value></Eq></Where></Query>', // query '<

Cannot create user: server cannot determine if it is member of a domain

Hi, An instance of our 2008 SP1 SQL Server is running on a computer that was removed from it's domain and then re-added. Now, when I want to create a new login in Management Studio via the nodes Security/Logins, selecting "New Login", entering DOMAIN_NAME\USER_NAME as login name and then click "Search", I get an error message (in German) "Das Programm kann das erforderliche Dialogfeld nicht öffnen, da nicht ermittelt werden kann, ob Computer "COMPUTER_NAME" einer Domäne zugeordnet ist. Schließen Sie dieses Dialogfeld, und wiederholen Sie den Vorgang". Translation: "The program cannot open the required dialog, as it cannot be determined if computer "COMPUTER_NAME" is assigned to a domain. Close this dialog, and repeat the process." But closing the dialog and repeating as suggested does not help. Even restarting the SQL Server service and re-connecting in Management Studio did not help. I keep getting this message. I found, however, that just entering the domain and user name and then clicking Ok seems to add the user. Anyway, it is irritating to get this error message when clicking "Search". How can I tell the engine that the computer is really member of the domain again? Frank


I am using Forms  Authentication. I set the cookie when user logs in. Welcome text =  HttpContext.Current.User.Identity.Name Logout = Session.Abandon and Session.Clear() Now when I logon using different user name i still see my previous login name when I do" HttpContext.Current.User.Identity.Name  

Get current logon user id with SPContext.Current.Web.CurrentUser.LoginName

Hi all,I've been trying to search for the method to display the currently logon user id. So far, most sites I've visited used SPContext.Current.Web.CurrentUser.LoginName.I've tried this in my SharePoint custom application page. Everything works great.I have a test account, when logged in, was displayed as xxx\testacc.For some reasons, I changed the id in AD to xxx\test and did a full import to MOSS.I logged in to the custom application with the changed id, i.e. xxx\test, BUT the value of SPContext.Current.Web.CurrentUser.LoginName still displayed as xxx\testacc!How do I get the latest id? Has anyone encountered this before?Thank you.Kelvin

How to check if a given user is local admin or not

Hi, How to check if a user (may be domain user also) is part of local administrators group or not? Note I am NOT talking about checking of current logged in user. I should send the username & passowrd of any user (may or may not be domain user) & that should flag me whether that user is local admin or not. Please help.

How to let a non admin business user run a replication snapshot job?

According to the msdn library, I would have to give the non admin user (User1) SQLAgentUserRole privileges. But it also says that it has to be a local job and not a multi server job. Is the snapshot agent job a local or multi server job? Considering the snapshot agent is a local job and i make USER1 the owner of that job. He should be able to run the job rite? I need to give USER1 the ability to run sp_start_job to start the snapshot agent ONLY! (and not any other jobs). So what are the steps to do this? I also read that the only way to achieve this is by creating a proxy account? Is there an article somewhere that best describes this?  

How to pass current user's login name as parameter to a RDL . (SSRS integration with sharepoint)

I have a webmethod which has two parameters. One is for year and another is for Currently logged in user. I call this method in RDL file. From RDL File how can we pass Currently logged in user's login name? I tried  with USER!UserID. It is passing the USERID but i need to pass the login name(SPWEB.currentuser.loginname)  

current user identity in custom security trimmer

The crux of my problem is that I want to impersonate  a user’s NTLM credentials in the context of a SharePoint custom security trimmer to execute HttpWebRequests to check user access to URLs.  When accessing WindowsIdentity.GetCurent() in the security trimmer, the System.Security.Principal.WindowsIdentity object returns the identity of the application pool running the search query service, NOT the currently logged in user.   When accessing System.Threading.Thread.CurrentPrinciple.Identity in the security trimmer, the Microsoft.IdentityModel.Claims.ClaimsIdentity object of the current logged in user is returned.  However, there is a catch.  …   If I execute the following code in a .NET web application, the cast of the ClaimsIdentity to a WindowsIdentity succeeds because the identity has the authentication type of NTLM.    WindowsIdentity winId = (WindowsIdentity)System.Threading.Thread.CurrentPrincipal.Identity; WindowsImpersonationContext wic = winId.Impersonate(); request.Credentials = CredentialCache.DefaultCredentials; //access means a response comes back when a request is made to the url using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { returnStatus = true; } wic.Undo(); However, when I execute the same code in the context of the SharePoint security trimmer (the search query service li

How to create a list filter like: get all list elements from the current user and all employees from

Hello, is it possible to filter elements by the condition mentioned in the title? Tobias

httpcontext.current.user.identity.isauthenticated always false

Dear, please help me, I create two pages, the first one is the login page with user name and password textboxes - (not asp login control) , when clicking login button I check the login authentication, if it is true redirect to default page. in the default page if !IsCallBack then i check httpcontext.current.user.identity.isauthenticated if it is false i redirect the user to the login page. but my problem is that the httpcontext.current.user.identity.isauthenticated is always false. Below the section of authentication in web config < <authentication mode="Forms">forms loginUrl ="FrmUserLogin.aspx"  protection ="All"  timeout ="1"  name ="LoginRedirectCallback"  path ="/LoginRedirectCallback"  requireSSL ="false"  slidingExpiration ="true"  defaultUrl ="FrmDBLoginConfigaspx.aspx"  cookieless ="UseDeviceProfile"   < < </   </ </enableCrossAppRedirects ="false">credentials passwordFormat="Clear">user name ="admin" password ="admin"/>credentials>forms>authentication> thank you for any help.   Best Regards,

how to get current logged in user in sharepoint

hi im trying to get current logged in user from sharepoint site. All im getting is domain/administrator. I tried following. SPUser and delegation with elevated privilege. they are also not working for me. following is the code im working. spsite site = new spsite("some site")  spweb web = site.openweb() then im using spuser object to get the user. i went to the following link but it seems that guy was also not able to do this.... http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/4101e616-db5d-4504-ad16-169ff62269fb/   any idea... thanks Aqi

How to add colleagues to a user profile without admin priviliges programatically ...

Hi,I am working on a kind of a social networking site and the use case is as follows.1. User A sends a friendship request to User B.2. User B accepts.3. User A is added as a colleague in User B's Profile.4. User B is added as a colleague in User A's Profile.Step 2-4 are done using User B's login. Step 2 and 3 go fine but in step 4 I get the following error "This operation requires you to be managing your own data or have administrator privileges.". The API being used is UserProfile.Colleagues.Create (...);What is required is obvious but not possible in this scenario. SPSecurity.RunWithElevatedPrivileges does not help.  Any other way of accomplishing this.Thanks.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend