System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

I'm not sure how many of you are using MSDE as your backend data store, but Web Matrix inborn work naturally with the MSDE Database. Even in the Guided Tour of Web Matrix (which is a tutorial for Web Matrix user and step-by-step samples for users) also have an appendix specialized in MSDE installation).

"Login Failed for user XXX\ASPNET" is a FAQ in the Forums, I think I saw and moderate this kind of questions over thousands of times. Dave post a FAQ for this subject some times ago, while an ASP.NET Team member - MikePope - answer a question for that problem again recently.

Abstract:

Colt's suggestion to enable impersonation causes ASP.NET to make the request to the SQL Server as the name of the user currently running -- probably you...

Using impersonation works if anyone who hits the site has Windows credentials. For your testing, that works for sure. If you're going to create a site that people might get to via the Internet, though, then impersonation won't work, because users won't have credentials. In that case, you probably don't want to use impersonation. Instead, the app can run in the context of the computer\ASPNET user and you can grant database privileges to that ASPNET user...


Personally, I think this lines of explanation is very clear and easy to understand, the point is that impersonation do work but enable ASPNET weaker account is the more practical for an Internet application. I like this simple English and his sample code in replying so I bookmark and blog it. :)

(The oSQL command and complete script can be found at here)

Published Thursday, July 10, 2003 9:07 PM by Colt
Filed under:

Comments

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

note the "sp_addrolemember 'db_owner', 'computer\ASPNET'" is probably too much as the dbo has full capabilites on the database. It's better to use one of the other roles such as db_datareader, or to apply the permissions at the object level.

Thursday, July 10, 2003 12:34 AM by cathal

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Oh yeah, thanks Cathal, it's a useful tips and practise to limit the access account to backend database all the times!

Personally, I'd create a user account and limit it to the weakest right and role when accessing to my database server :)

Thursday, July 10, 2003 4:38 PM by Colt

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Hi!

I had the same problem, but it worked very well!!

this done the trick!

Wednesday, February 11, 2004 7:14 PM by Héctor M. Castro

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Hi,
I am getting the same error: Login failed for user 'machinename\ASPNET'.
I created a user account names machinename\ASPNET for the database (I want to access) and then I don't know how to create a user for the datbase server and how to "limit it to weakest right and role when accessing to my database server".
Can somebody plz plz plz help me?
Thanks

Wednesday, March 10, 2004 10:00 AM by Rachel

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Hi,
1. If you are using a sql-server database, open enterprise manager. (The enterprise manager will be available within the sqlserver program group in windows. Start->Programs->Microsoft SQL Server->enterprise manager)

2. In the ( database window ( left pane ) locate your database and expand. You will see tables, view, users etc listed below. Dblclick the users icon. On the right pane dblclick the machiname\ASPNET user you had created earlier. This will open up the "database user properties" window. You will see that the database role "public" is already selected.

3. Now additionally select the db_datareader role as well. Click apply.

This will give the database read permission to the ASPNET user and hopefully fix your problem.

Indranil

Friday, April 23, 2004 10:22 AM by Indranil

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Hi Indranil,

I don't know whether Rachel could do it, but this trick helped me.

Thanx.
Pans

Tuesday, May 25, 2004 5:35 PM by Pans

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Hi,
the solution given by Indranil, wprks perfectly.

Wednesday, June 02, 2004 9:47 AM by Vipul

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

If you are using SqlDataAdapter.Update to update a DataSet, make sure that the SqlConnection is set for all commands that are being used (InsertCommand,DeleteCommand), not just the UpdateCommand, or you may receive the unexpected Login Failed for User exception.

Wednesday, June 09, 2004 9:28 PM by Dan Mikell

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

thats all fine if you're using sql server but what if its only MSDE - then you don't get the option to add user accounts via enterprise manager

Thursday, July 29, 2004 11:32 PM by db

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

For $22 US, I bought MSDE Admin, from RegSoft.com. Their download site is
www.hotdownloads.com
which says it's "powered by" RegSoft.
In the search box, enter "MSDE Admin" and you'll be taken to a page showing six items - you'll probably want the second one, MSDE 1.0 for SQL Svr 7.0 and MSDE/2000 for SQL Svr 2000.

It is slightly less robust than SQL2K's Enterprise Manager, but hey, for the money, it lets you do most of the things you'd want. The minor differences mean you sometimes won't be able to directly follow examples in SQL for Dummies.

Regards, RR

Friday, July 30, 2004 1:58 AM by RandyR

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

I am getting the  error: Login failed for user 'machinename\ASPNET'.

Monday, May 21, 2007 8:51 AM by sandeep

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

I done it but still it is not working.

Sunday, May 27, 2007 11:38 AM by Farhan

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

i had doine following thing to solve this problem.

1. Created a new user of ASPNET in sql server and given all type access to it throught properties.

2. I had checked the server authentication mode. It is set to windows and SQL server which is correct i think.

3. I have added "trusted connection = yes;" in connection string.

I have sql server 2000 and asp.net 1.0. My windows is windows server 2000. Can any one help me. i will be so thankful to him.

Sunday, June 03, 2007 5:43 AM by Farhan

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Created sql connection

created sql adapter

I am not able to geenrate dataset.

please help me.

Wednesday, July 04, 2007 11:49 PM by asmita

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

hi, can any one help me out of this

 in sql server enterprise manager

  i have

  microsoft SQL Server

   SQL Server Group

     no item

Wednesday, July 11, 2007 12:48 AM by mohit

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

I faced the same problem "System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'". I tried the trick Indranil suggested. It worked. Thanx...Thanx a lot.... Indranil

Monday, July 23, 2007 1:59 AM by Saravanan

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Very good. Thanks a lot

Friday, July 27, 2007 6:28 AM by Sun Jiang

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

my db connection string is using user 'emaplerc' but in the error generated, it says 'Login failed for user 'PLESK003\IWAM_plesk(default)'

please help...thanks

Saturday, July 28, 2007 12:25 PM by james

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

System.Data.SqlClient.SqlException: Login failed for user 'STTL05\Guest'.

  at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)

  at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)

  at System.Data.SqlClient.SqlConnection.Open()

  at TEMP.Loginform.btnok_Click(Object sender, EventArgs e) in C:\Library Management System\loginfrom.vb:line 339

  at System.Windows.Forms.Control.OnClick(EventArgs e)

  at System.Windows.Forms.Button.OnClick(EventArgs e)

  at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

  at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

  at System.Windows.Forms.Control.WndProc(Message& m)

  at System.Windows.Forms.ButtonBase.WndProc(Message& m)

  at System.Windows.Forms.Button.WndProc(Message& m)

  at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)

  at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)

  at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Tuesday, August 07, 2007 5:17 AM by kiran

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Hi,

the solution given by Indranil, wprks perfectly.

Nixson

Friday, August 17, 2007 1:20 AM by Nixson

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Ay ideas for solving this problem for SQL Server Express?  

Saturday, September 22, 2007 5:13 PM by Emm

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Hi

I have The Same Problem "System.Data.SqlClient.SqlException: Login failed for user 'MachineName\guest'" where i try to connect to another computer by using windows aplication

Saturday, November 17, 2007 3:30 AM by hiba

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Did every thing that has to be done this is my web.config connection string

<connectionStrings>

<add name="sqloledb" connectionString="Data Source=mssql10.oneandone.co.uk,1433;Initial Catalog=db230311820;Integrated Security=True; User ID=dbo230311820; Password=HB7EArFn" providerName="System.Data.SqlClient" />

<remove name="LocalSqlServer"/>

<add name="LocalSqlServer" connectionString="Data Source=mssql10.oneandone.co.uk,1433;Initial Catalog=db230311820;Integrated Security=True;User ID=dbo230311820; Password=HB7EArFn" providerName="System.Data.SqlClient" />

</connectionStrings>

as soon as i get to login to my website (hosted by 1and1 ) I get this error:

Login failed for user 'HOSTINGXP\NTXPW33$'.

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 'HOSTINGXP\NTXPW33$'.

Source Error:

Line 14:     protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)

Line 15:     {

Line 16:         if (Membership.ValidateUser(Login1.UserName, Login1.Password))

Line 17:         {

Line 18:             FormsAuthentication.SetAuthCookie(Login1.UserName, Login1.RememberMeSet);

Source File: E:\kunden\homepages\33\d213481365\NewJob\login.aspx.cs    Line: 16

any ideas guys, am I doing something wrong here???

Sunday, January 06, 2008 8:33 AM by youjet

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

System.Data.SqlClient.SqlException: Login failed for user 'BOKHOSYSTEM03\ASPNET'.

Monday, January 21, 2008 11:43 PM by ummmmm

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Login failed for user 'GLA-08E851E4D14\ASPNET'

help

help

helphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelp

helphelphelphelphelphelphelphelphelp

help

help

help

help

Saturday, January 26, 2008 2:11 PM by nhfj

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Login failed for user 'O360-FW73OVB4SG\ASPNET'.

Tuesday, January 29, 2008 1:40 AM by bv

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

thanks its work for me

Wednesday, April 16, 2008 12:05 AM by edooredi96

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

it is working when it is not published but grtting error in IIS?

suggest Solution

Thanks

Tuesday, April 29, 2008 12:43 AM by arti.manathkar

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

I got same problem. Now i could resolve the problem by your comments

Friday, May 02, 2008 4:11 AM by thiru

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Thanks for Indranil

Thursday, May 08, 2008 1:29 AM by anar

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

sorry to said that

but realy i do waht Indranil do to solve this problem but the problem still not workin , please if any one can help send comment

it still not Working

Thursday, June 26, 2008 1:13 PM by mohamed

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

hi, it's very simple  just goto  "controlpanel=>user accounts " and change the type of user for ASPNET to Administrator, it will solve the problem.

Monday, August 25, 2008 7:44 AM by gowda

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

hi there,

I am using .Auth and have the membership provider configured in the config file with a correct connection string.

When I run the code via a unit test then everything is OK but when I run the code via ASP.NET application I get the  'Login failed for user XXX\ASPNET' error.

Do you have any idea why the ASPNET login is used an not the one I specifically defined in the config? ASPNET is not even a login in SQL...

Many thanks

N

Wednesday, September 24, 2008 11:53 AM by NNZZ

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Microsoft sql server -> enterprise manager.

Microsoft SQL Server

SQL Server Group

serverName\VSDOTNET (Windows NT)

Security

Logins <right click>

New Login

Name <click ....>

scrolll down to the ASPNET (aspnet wp account)

You can set default database if you wish here too.

Friday, October 24, 2008 8:58 AM by Jesús

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

i followed the steps Indranil

indicated, but I still get the same error message, Login failed for user 'DOMAIN\SERVER$'.  Also, I do not see a 'public' role option in SQL 2005 Database User Properties.  My web.config is:

<connectionStrings>

  <add name="TiresConnectionString" connectionString="Data Source=DOMAIN\(INSTANCE17);Initial Catalog=TiresDb;Integrated Security=True"/>

 </connectionStrings>

<configProtectedData>

<providers>

<add useMachineProtection="false" keyEntropy="" name="TiresDataProtectionConfigurationProvider"

type="System.Configuration.DpapiProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0,Culture=neutral,

PublicKeyToken=b03f5f7f11d50a3a"></add>

</providers>

</configProtectedData>

<system.web>

<authentication mode="Windows"/>

   <roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider"

               cacheRolesInCookie="true" createPersistentCookie="false" cookieProtection="All">

     <providers >

       <remove name="AspNetSqlRoleProvider" />

       <add name="AspNetSqlRoleProvider" applicationName="Tires"

             connectionStringName="TiresConnectionString"

            type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral,PublicKeyToken=B03F5F7F11D50A3A"/>

       <remove name="AspNetWindowsTokenRoleProvider" />  

     </providers>

   </roleManager >

   <authorization>

     <allow roles ="Admin, Supervisor, User"/>

     <allow users ="DOMAIN\(INSTANCE17) Users,DOMAIN\(INSTANCE17) Supervisors, DOMAIN\(INSTANCE17) Admin Users"/>

<deny users="*"/>

</authorization>

   <identity impersonate="true"/>

<customErrors mode="Off" defaultRedirect="UnauthorizedUser.aspx">

<error statusCode="401" redirect="UnauthorizedUser.aspx"/>

</customErrors>

What do I need to change to get this working?!?!

Tuesday, October 28, 2008 9:35 AM by Ayomide

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

I followed the steps given by still have this problem. Help! I made another user 'Me' with permissions to the database I wanna access but still have this >.<

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'Me'.

Source Error:

Line 11:

Line 12:         ' Open the connection

Line 13:         connection.Open()

Line 14:

Line 15:         ' Return a SqlDataReader to the calling function

Source File: C:\BegECom\VidzDownloads\BusinessObjects\Catalog.vb    Line: 13

Stack Trace:

[SqlException: Login failed for user 'Me'.]

  System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)

  System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)

  System.Data.SqlClient.SqlConnection.Open()

  VidzDownloads.Catalog.GetDepartments() in C:\BegECom\VidzDownloads\BusinessObjects\Catalog.vb:13

  VidzDownloads.DepartmentsList.Page_Load(Object sender, EventArgs e) in C:\BegECom\VidzDownloads\UserControls\DepartmentsList.ascx.vb:42

  System.Web.UI.Control.OnLoad(EventArgs e)

  System.Web.UI.Control.LoadRecursive()

  System.Web.UI.Control.LoadRecursive()

  System.Web.UI.Control.LoadRecursive()

  System.Web.UI.Page.ProcessRequestMain()

Sunday, November 02, 2008 4:48 AM by Nic

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

My problem is similar like this. My code here:

in the web config:

<connectionStrings> <add name="IAConnectionString" connectionString="Data Source=166.118.210.27;Initial Catalog=IA;Integrated Security=True" providerName="System.Data.SqlClient"/>

</connectionStrings>

<authentication mode="Forms">

<forms name=".COOKIEDEMO"

loginUrl="Login.aspx"

protection="All"

timeout="30"

path="/"/>

</authentication>

<authorization>

<deny users="?"/>

</authorization>

And in the login.aspx page

<html xmlns="www.w3.org/.../xhtml" >

<script language="C#" runat="server" >

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]

public static extern int LogonUser(String lpszUserName,

String lpszDomain,

String lpszPassword,

int dwLogonType,

int dwLogonProvider,

ref IntPtr phToken);

public const int LOGON32_LOGON_INTERACTIVE = 2;

public const int LOGON32_PROVIDER_DEFAULT = 0;void Login_Click(Object sender, EventArgs E)

{

IntPtr token = IntPtr.Zero;

if(LogonUser(UserName.Value,

UserDomain.Value,

UserPass.Value,

LOGON32_LOGON_INTERACTIVE,

LOGON32_PROVIDER_DEFAULT,

ref token) != 0)

{

FormsAuthentication.RedirectFromLoginPage(UserName.Value,

PersistCookie.Checked);

}

else

{

lblResults.Text = "Login Failed, Please Try Again!";

}

}

</script>

when I run a page after login:

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'HCMSAPP01\IUSR_HCMSAPP01'.

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 identified using the exception stack trace below.  

Stack Trace:

[SqlException (0x80131904): Login failed for user 'HCMSAPP01\IUSR_HCMSAPP01'.]

  System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800131

  System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186

  System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932

  System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +33

  System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +172

  System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +381

  System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +181

  System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +173

  System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +357

  System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +30

  System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424

  System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66

  System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +494

  System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82

  System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105

  System.Data.SqlClient.SqlConnection.Open() +111

  System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121

  System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137

  System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +83

  System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1770

  System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17

  System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149

  System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70

  System.Web.UI.WebControls.GridView.DataBind() +4

  System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82

  System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69

  System.Web.UI.Control.EnsureChildControls() +87

  System.Web.UI.Control.PreRenderRecursiveInternal() +50

  System.Web.UI.Control.PreRenderRecursiveInternal() +170

  System.Web.UI.Control.PreRenderRecursiveInternal() +170

  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

After I make Login.aspx page base on Window account domain ( for intranet ) and after login success I've got the error :

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'HCMSAPP01\IUSR_HCMSAPP01'

In warning: 'HCMSAPP01': server

              'IUSR_HCMSAPP01' may be User ID

Please help me for solution to fix this problem. Thanks All

Friday, November 07, 2008 3:19 AM by suvn99

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

My problem is similar like this. My code here:

in the web config:

<connectionStrings> <add name="IAConnectionString" connectionString="Data Source=166.118.210.27;Initial Catalog=IA;Integrated Security=True" providerName="System.Data.SqlClient"/>

</connectionStrings>

<authentication mode="Forms">

<forms name=".COOKIEDEMO"

loginUrl="Login.aspx"

protection="All"

timeout="30"

path="/"/>

</authentication>

<authorization>

<deny users="?"/>

</authorization>

And in the login.aspx page

<html xmlns="www.w3.org/.../xhtml" >

<script language="C#" runat="server" >

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]

public static extern int LogonUser(String lpszUserName,

String lpszDomain,

String lpszPassword,

int dwLogonType,

int dwLogonProvider,

ref IntPtr phToken);

public const int LOGON32_LOGON_INTERACTIVE = 2;

public const int LOGON32_PROVIDER_DEFAULT = 0;void Login_Click(Object sender, EventArgs E)

{

IntPtr token = IntPtr.Zero;

if(LogonUser(UserName.Value,

UserDomain.Value,

UserPass.Value,

LOGON32_LOGON_INTERACTIVE,

LOGON32_PROVIDER_DEFAULT,

ref token) != 0)

{

FormsAuthentication.RedirectFromLoginPage(UserName.Value,

PersistCookie.Checked);

}

else

{

lblResults.Text = "Login Failed, Please Try Again!";

}

}

</script>

when I run a page after login:

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'HCMSAPP01\IUSR_HCMSAPP01'.

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 identified using the exception stack trace below.  

Stack Trace:

[SqlException (0x80131904): Login failed for user 'HCMSAPP01\IUSR_HCMSAPP01'.]

  System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800131

  System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186

  System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932

  System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +33

  System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +172

  System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +381

  System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +181

  System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +173

  System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +357

  System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +30

  System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424

  System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66

  System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +494

  System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82

  System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105

  System.Data.SqlClient.SqlConnection.Open() +111

  System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121

  System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137

  System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +83

  System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1770

  System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17

  System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149

  System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70

  System.Web.UI.WebControls.GridView.DataBind() +4

  System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82

  System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69

  System.Web.UI.Control.EnsureChildControls() +87

  System.Web.UI.Control.PreRenderRecursiveInternal() +50

  System.Web.UI.Control.PreRenderRecursiveInternal() +170

  System.Web.UI.Control.PreRenderRecursiveInternal() +170

  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

After I make Login.aspx page base on Window account domain ( for intranet ) and after login success I've got the error :

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'HCMSAPP01\IUSR_HCMSAPP01'

In warning: 'HCMSAPP01': server

              'IUSR_HCMSAPP01' may be User ID

Please help me for solution to fix this problem. Thanks All

Friday, November 07, 2008 3:25 AM by suvn99

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

great source to resolve the problem.

Tuesday, November 11, 2008 4:10 AM by abidshahzad

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

thanks a lot Indranil

Friday, November 28, 2008 1:37 AM by Silpa

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

It worked for me too Thanks...

Tuesday, December 02, 2008 1:52 AM by Nan

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Hi,

I am unable to establish a connection rom NetCOBOL to SQL Server.

I get an error:

JMP0371I-U [PID:00000788 TID:0000025c]  ENVIRONMENT INFORMATION FILE ERROR TO PERFORM SQL. '@SQL_SERVER'. PGM=Test.Program1

I do not have the SQLODBCS.exe to create an environment information file.

Please help.

Wednesday, December 17, 2008 8:46 AM by Supriya Tenany

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Configure the SQL Server

To permit an ASP.NET application that executes in the context of the ASPNET account to access an SQL Server database, follow these steps:

  1. On the taskbar, click start.

  2. Point to Programs and then point to Microsoft SQL Server.

  3. Double-click Enterprise Manager.

  4. Expand Microsoft SQL Servers and then expand the SQL Server group that contains your server.

  5. Expand your server branch and then expand Security.

  6. Right-click Logins and then select New Login to open the SQL Server Login Properties-New Login dialog box.

  7. Click the General tab. In the name field, enter the name of the ASP.NET user. example - ASPNET . This should bring search and higlight you machinename/ASPNET.In my case it showed up something like 'VKASIVIS/ASPNET' which is what is required.

8.restart the sqlexpress services and thatz it...

Saturday, January 03, 2009 1:19 PM by Vivek

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

thanks Indranil

anyone having the same problem, follow Indranil answer.

Wednesday, February 25, 2009 12:37 AM by Muhammad tabish

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Creating new Login worked for me. Thanks Vivek.

Monday, March 16, 2009 10:02 AM by zzo

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Thanks for solutions to Vivek and Indranil, now it's running great!

Friday, May 08, 2009 11:10 AM by Alex

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Sunday, May 17, 2009 11:04 PM by nick_c4tlac

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

HI!!

My solution:

include this line in the webconfig, after the <authentication mode="Windows"/> :

<identity impersonate="true" />

bye

Wednesday, June 10, 2009 2:58 AM by xuanxoo

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

username which appears in error does not exist anywhere in DB.

why such random username in error?

Wednesday, June 10, 2009 2:13 PM by praj

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Thanks Indranil..

i have solutions to follow Indranil procedure.

                                        Dinesh

Tuesday, June 16, 2009 2:44 AM by Dinesh

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

my question solved too.

i had given wrong definition of connectionstring in web.config file. once i corrected path for connectionstring, error got resolved.

Tuesday, June 16, 2009 1:20 PM by praj

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Login failed for user 'VOLLER\ASPNET'.

this same error i am getting again and again..

created new user and granted all the database permissions even then it is the same..

i ve a second thought of my web.config file ..

i think there might something wrong with the connection string..

please help..

my web.config file is below...

and Bear is my databse name(using SQL server management studio express.)

<connectionStrings>

   <remove name="LocalSqlServer" />

   <add name="LocalSqlServer" connectionString="Data Source=VOLLER;Initial Catalog=clg;Integrated Security=True" providerName="System.Data.SqlClient" />

   <add name="Site1ConnecctionString" connectionString="Data Source=VOLLER;Initial Catalog=clg;Integrated Security=True" providerName="System.Data.SqlClient" />

   <add name="BearConnectionString" connectionString="Data Source=VOLLER;Initial Catalog=Bear;Integrated Security=True" providerName="System.Data.SqlClient" />

 </connectionStrings>

Friday, July 10, 2009 5:01 PM by Prof

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

Thanks you so much Indranil, Your suggetion helped me lot!!

Monday, July 20, 2009 10:27 AM by Bijal

# re: System.Data.SqlClient.SqlException: Login failed for user 'MachineName\ASPNET'

hi, can you me ?

I have an error like :

Server Error in '/balloonshop' Application.

--------------------------------------------------------------------------------

Login failed for user 'sa password=sohil'.

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 'sa password=sohil'.

Source Error:

Line 17:         SqlConnection con = new SqlConnection();

Line 18:         con.ConnectionString = "Data Source=SHIVANI;Initial Catalog=balloonshop;Persist Security Info=True;User ID=sa password=sohil";

Line 19:         con.Open();

Line 20:

Line 21:         SqlCommand cmd = new SqlCommand();

Source File: d:\balloonshop\Default.aspx.cs    Line: 19

Tuesday, July 28, 2009 5:06 AM by sohil

Leave a Comment

(required) 
(required) 
(optional)
(required)