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

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

Adding Current Windows User to Database Encounters Existing User with Same Login

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :Sql Server

In VS2008 in debug mode, I am using SMO to programatically change the users and permissions on a database. Windows authentication alone is being used. I need to limit access to a administrators group and the current user for whom the database has been dynamically created during the first run of the application within their current Windows environment on the machine. I have no problems creating and assigning the administrators group, but when I try to create the user using the environment's UserDomainName and UserName variables (which would be my creditals) I encounter an inner exception "The login already has an account under a different user name". Before doing running the app, I manually have checked the local server for user and logins with my credentials and programatically looked at each login but have not found any matching credentials. 

Insights and suggestions appreciated.


View Complete Post

More Related Resource Links

Forms based users being prompted for windows authentication login for My Sites photos in user lists

Here's an issue I didn't see coming for our forms based authentication users. 

We have a web application extended to an external url to handle forms based authentication for users outside of our domain. Our setup looks like this...

Internal Users/Windows Authentication - moss.domain.com
External Users/Forms Based - mossext.domain.com
My Site for Internal Users - mysites.domain.com

When our forms based users are accessing user lists, or discussion pages that display user pictures, they are getting a windows authentication login for our internal users (mysites.domain.com) who have populated their my site with personal photo.

How do we fix this? 

=User!UserID from windows authentication using table from another database



i'm using sql server 2005, sql server business intelligence development studio for my reports and deploy them in my wss3.0 site.

what i'm trying to do is i'm trying to restrict wich users can see specific data within a report.

now, the thing is. the report gets the data out of my DB1 database and my windows authenticated user are in the WSS_content database.

when i deploy my report in my wss3 site. it gets the user that is loged in. but of course it does not display any data because the tables are not in the same database.

does someone knows how to do 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)  

Can I have an SQL Express database open in VS2010E along with the website? "Login failed for user ..

Hi, as the topic says..Whenever I have my database open in Visual Studio 2010 Express, I get this error:Cannot open user default database. Login failed.Login failed for user 'IIS APPPOOL\DefaultAppPool'.Cannot open user default database. Login failed.Login failed for user 'IIS APPPOOL\DefaultAppPool'.

Associate Existing User to Login

Hello, I am creating a login and then associating an existing user to that login and also to a role: -- Define login create login [$(DatabaseName)] with password = '@Password', check_policy = off, check_expiration = off, default_database = [$(DatabaseName)], default_language = english; -- Associate user exec sp_change_users_login 'Update_One', N'FOP', '$(DatabaseName)'; -- Define role grant select, insert, update, delete, execute on schema::dbo to Application; exec sp_addrolemember @membername = N'FOP', @rolename = N'Application' What ever I do I get the following error: Procedure sp_change_users_login, Line 114 Terminating this procedure. The User name 'FOP' is absent or invalid. On this code line: exec sp_change_users_login 'Update_One', N'FOP', '$(DatabaseName)'; How can the user be invalid if even after this code line I am able to associate it with the role with no problem. Could someone please tell me what is going on? Thank you, Miguel

adding database user as a DBO

Hi there - I'm a SQL newbie I have a T-SQL script I've been working on. Currently it's in 2 parts and both parts work if I run then separately - my question is - can they be combined? Part 1: Creates a new DB CREATE   DATABASE LUCY_Config ON PRIMARY (   NAME = N'LUCY_Config', FILENAME = N'Q:\MSSQL\DATA\LUCY_Config.mdf' , SIZE = 1024MB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024MB ), FILEGROUP   FG1 DEFAULT ( NAME = N'LUCY_Config_Dat1', FILENAME = N'Q:\MSSQL\DATA\LUCY_Config_Dat1.ndf' , SIZE = 1024MB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024MB),   (NAME = N'LUCY_Config_Dat2', FILENAME = N'Q:\MSSQL\DATA\LUCY_Config_Dat2.ndf' , SIZE = 1024MB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024MB),   (NAME = N'LUCY_Config_Dat3', FILENAME = N'Q:\MSSQL\DATA\LUCY_Config_Dat3.ndf' , SIZE = 1024MB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024MB)   LOG ON (   NAME = N'LUCY_Config_Log', FILENAME = N'Q:\MSSQL\DATA\LUCY_Config.ldf' , SIZE = 250MB , MAXSIZE = UNLIMITED , FILEGROWTH = 1024MB ) Collate   Latin1_General_CI_AS_KS_WS Go ***************** Part 2 - adds a user as a DBO - use   [LUCY_Config]   IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'moss2\setup')   CREATE USER [moss2\setup] FOR LOGIN [moss2\setup];   EXEC sp_addrolemember N'db_owner', N'moss2\setup'

general error login failed for user '' on windows 2008 in application that runs correctly on windo



we have a web application that one company prepared for us. this application read connection string from registery key in hkey_local_machine and connect to sql server 2005 database.

It worked correctly in windows server 2003. we changed our Server'OS to windows server 2008. but we have a problem to login. after try to login we see this error :

Login failed for user ''. The user is not associated with a trusted SQL Server connection.

Server Error in '/dabir' Application.

Login failed for user ''. The user is not associated with a trusted SQL Server connection.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user ''. The user is not associated with a trusted SQL Server connection.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be

adding windows user control in asp.net application


hi fri i had created one user control in c# and i want to add this user control in asp.net application pl tel me how to do this

thanks in advance

Adding existing user to existing group - Unknown error (0x80005000)


I am getting an unknown error 0x80005000.  Please help!

I am using impersonation of an admin account. Here's what I have in my web.config:

<identity impersonate="true" userName="mydomain\user" password="pwd"/>

<authentication mode="Windows" />


Here's my code:

Private Sub Page_Load(ByVal sender As System.Object, <

How can I filter a Sharepoint 2007 libarry list based on current user login?


Hi all.

I would like to know how I can filter a SharePoint library list based on current user login.

Suppose I have created the followings:

1) A SharePoint form library containing bunch of uploaded InfoPath form data.

2) The InfoPath form template contains a promoted text field called "TargetUser" to store user domain login (ex: DOMAIN\JOE) and every InfoPath form file in the library has a valid domain name stored in the "TargetUser" field.

I have created a custom view for the form library and would like to filter this view so only items whose "TargetUser" field matches current user's login ID are displayed.

I went to Edit View page to customize the view and tried to use the [Me] function but I got a "Filter value is not a valid text string" message instead when clicking OK. Apparently [Me] returns a Person/Group data type and the filter cannot compare its value to that of "TargetUser".

I tried using text functions (ex: TEXT([Me],"") hoping to extract default string value from [Me]. The filter accepts the parameter without any error but the resulting fitlered list does not display any items at all.

I have googled this subject for hours but I have not found any solution.

It would be greatly appreciated if anyone can help me t

How to get current user session in Windows application C#?



I am trying to create a Windows Application similar to facebook friend finder.exe in .NET. The steps I have followed to achieve this is as follows:

1. I have created a webservice containing webmethod SaveContacts(string firstname, string lastname, string number, string photo, string email, string userid).


2. I am consuming the webservice in a Windows Form application and calling the above mentioned function.

Now, I want to get the current logged in user ID which through the windows form application which is something tedious to me.

If anyone have any idea how to achieve this. Please help.






Not able to get current windows user in RS2005 (but same code works for RS2000)


We use the following custom code (checkGroupMembership.dll) to get identity of the current windows user and then check if the user is part of a certain group (roleName in code below).  

SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.ControlPrincipal);
WindowsIdentity wi = WindowsIdentity.GetCurrent();
WindowsPrincipal cPrincipal = new WindowsPrincipal(wi);    
isMember = cPrincipal.IsInRole(roleName);

The code above behaves differently for RS2000 vs. RS2005. Both RS2000 and RS2005 are installed on same server. If I use the following code to check the WindowsPrincipal name, I get the expected result (my windows login ID) when called from a report in RS2000 but for RS2005 I get the user id of reporting services.


I have checked rssrvpolicy.config (for both RS2000 and RS2005) and it has the same permission for checkGroupMembership.dll.

Any suggestions on why the same code will get different WindowsIdentity? Where I should look next? Any help would be greatly appreciated.


Windows 7 - User needs to login again in sharepoint


Hi there,

i hope this is the correct forum for this question. I need help with this issue:

Every Morning, a user [Windows 7/Office 2007/IE 8] needs to authenticate again when he opens sharepoint for the first time.

In the IE-Settings i tried to put the the sharepoint site to the trusted sites and set the authentication to automatic authentication with current user and password.
That did not help. I also tried to put the sharepoint site to intranetzone  aswell but that did not help either (automatic authentication enabled).

When i set these settings for a Win XP-User, it works like a charm - no extra authentication for the sharepoint will pop up. So i think its something with windows 7.
I've heard about some registry values to be set. But to hack something into the registry of a customer pc seems to me like the last exit.

Are there any other (better) solutions/settings which i can try ?

How to get WIndows Current User without Anonymus Access


Hi All,

We have developed an web application, that should run with Active Directory users. That is working fine in our local machines, but when we hosted this into client environment, we are unable to  get the Current User, it is returning NULL.

Could you please give a solution to us.


Thanks in Advance,

Sateesh Nagalla. 

Cannot open database "db" requested by the login. The login failed. Login failed for user 'NT AUTHO


I am working with visual studio 2010, ms sql server 08 R2, IIS 7.5, I am trying to connect to the database the following error appear every time I try to open the connection with the server:

Cannot open database "db" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Cannot open database "db" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.

Source Error: 

Line 47:             //    "','&qu

DirectorySecurity / calculating effective rights for the current windows user?


How do you calculate the effective rights for the current windows user and a specified directory?  I see how you can retrieve the DACL for a Directory using: Directory.GetAccessControl.  

I see that you can get all the access rules for the DACL using: 

var authRules = myDirectorySecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));


This seems to return all acess control entries for the given DACL.  I need to determine the effective rights for the current windows user against a give directory.

How can I retrieve or calculate the effective rights for a given user on a given folder? I basically need to determine if the current windows user has read/write/delete permissions for a given folder.


















Adding Certificates for SSL connection for a user account in Windows 2008 Server


Hi All, I have a windows service running on Windows 2008 server, when I set the service to log on as Local System account, it works fine and does the ssl certificate authentication.

Where as when I change the service to log on to a different account it fails with the authentication error.

Could some one please help me here.


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