IIS to SQL Server logging in with username that doesn't exist - c#

i am having no problem at all compiling/debugging my web app, but when i try to run it from my IIS server i get this error:
Server Error in '/' Application.
Login failed for user 'MLABS\STUDENT-006$'.
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 'MLABS\STUDENT-006$'.
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 'MLABS\STUDENT-006$'.]
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +578
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +88
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6275911
System.Data.SqlClient.SqlConnection.Open() +258
RadarGraphInsertDLL.LOMDLL.Get_Last_Lom() in c:\users\agordon\documents\visual studio 2008\projects\lomdb\enterdata\radargraphdll\radargraphinsertdll\lomdll.cs:212
EnterData.DataEntry.LOMForm.Page_Load(Object sender, EventArgs e) in C:\Users\agordon\Documents\Visual Studio 2008\Projects\lomdb\EnterData\DataEntry\LOMForm.aspx.cs:20
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
Version Information: Microsoft .NET Framework Version:2.0.50727.5448; ASP.NET Version:2.0.50727.5420
STUDENT-006 is my computer name it is not my username! i do not understand why it is trying to login with my computer name.
when the application is run, it immediately should pull data from the database. i have windows authentication enabled and it works without a problem when i run from dubugger, but when i try to compile i get the above error
what am i doing wrong?

MLABS\STUDENT-006$ is the username that the IIS application pool is running as. You either change the application pool user in IIS,
Open IIS Manager. For information about opening IIS Manager, see Open IIS Manager (IIS 7).
In the Connections pane, expand the server node and click Application Pools.
On the Application Pools page, select the application pool for which you want to specify an identity, and then click Advanced
Settings in the Actions pane.
For the Identity property, click the ... button to open the Application Pool Identity dialog box.
If you want to use a built-in account, select the Built-in account option and select an account from the list.
If you want to use a custom identity, select the Custom account option and click Set to open the Set Credentials dialog box. Then type
the custom account name in the User name text box, type a password in
the Password text box, retype the password in the Confirm password
text box, and then click OK.
Click OK to dismiss the Application Pool Identity dialog box.
or you can impersonate in web.config.
<configuration>
<system.web>
<identity impersonate="true"/>
</system.web>
</configuration>

MLABS\STUDENT-006$ is the account that the local "NETWORK SERVICE" account looks like when connecting to other machines and how the server is registered in Active Directory.
This is what the Application Pool in IIS running under, so this connects to SQL Server.
I'd suggest using a domain account especially for this

Related

IIS SQL Server configuration

I have a C# ASP.net project which was developed using Visual studio for web 2013 and SQL Server express 2012.
I used a database connection line as follows:
SqlConnection objConnection = new SqlConnection("Data Source=.\\MYDB;Initial Catalog=MYDB;Integrated Security=true");
objConnection.Open();
This worked fine when in developer mode in Visual Studio - but now I have deployed to IIS which runs under user IIS_IUSRS(Andy-PC\IIS_IUSRS).
When I visit my pages they then throw the following error:
Server Error in '/' Application.
Cannot open database "MYDB" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\MYDB'.
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 "MYDB" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\MYDB'.
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): Cannot open database "MYDB" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\MYDB'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +6749670
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +815
System.Data.SqlClien
Its pretty self explanatory - my connection string with integrated security=true is not successfully working as the current logged in user is not IIS_IUSRS.
Can somebody please help to show what I should alter the connection string to in order to create the connection when connecting as this new IIS user?
You need to change the user that your application pool is running as.
Go to Advance Setting for the Application Pool and change the Identity to a user that can access your sql server.
Actually you can use that connection string, just grant permissions to IIS APPPOOL\MYDB in your SQL server and database.
Using an explicit account for the site may make managing security easier in the long run, e.g. placing a connection string in the Web.config file for your ASP .NET project like:
<add name="SiteDB"
connectionString="Data Source=HostName\SQLServerInstance; Initial Catalog=MyDB; User Id=MyFirstWebsite; Password=secret"
providerName="System.Data.SqlClient"/>
Then using ConfigurationManager to get the connection string.
When there are several sites on the server this will make it clear which database this site should be using and, if several of the sites share the database, you can have them use different credentials so that they can have different access restrictions.

The system can't find specify file when using iis to broswer home.aspx file?

I write a asp.net website,but when i brower it in iis,and it tips:
Exception: System.ComponentModel.Win32Exception: system can't find specify file。
Source error:
[Win32Exception (0x80004005): The system can't find specify file.]
[SqlException (0x80131904): an instance error associate with network occured when link to SQL Server .Can't find or access to server.Please verify instance name is correct and SQL Server aready configurationa remote link avaliable . (provider: Named Pipes Provider, error: 40 - can't open SQL Server linker)]
EcaClient.ECAService.EcaClientService.GetUserModulePermission(Int32 userId, String moduleType) +120
EcaPortal.CSNavigation.GetCurrentUserModule() in E:\CucEcaPortal\CSNavigation.aspx.cs:113
EcaPortal.CSNavigation.Page_Load(Object sender, EventArgs e) in E:\CucEcaPortal\CSNavigation.aspx.cs:26
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
This is what i aready do:
1.Check the connection string,it is aready correct.
2.reconfiguration the portal in iis.
3.give the portal folder read/write privillege to everyone.
4.restart the iis
5.Search the error from internet if has any usable suggestion.
PS:Yesterday my website is correct and can broswer normal.
the w3wp.exe aways show form and needed visual 2010 to let me debug.
And when i check the process the w3wp.exe using a user name like:Default app pool,is it normal?
Why the iis find path from other location?
My aspx file location is:
E:\appserver\service\CucEcaPortal\CSNavigation.aspx.cs
but it just find from
E:\CucEcaPortal\CSNavigation.aspx.cs
Simply follow these steps,you will get rid to this error:
1.Reset IIS (Start>Run>IIsreset.exe)
2.Clear Cache (Ctrl+Shift+Delete Then Click Clear Now)
3.Clear Temporary File(Start>Run>%Temp% Then Enter,and Delete all Files)
4.Recycle your Website In IIs
5.Stop/Start SQL Servies( Start>Control Panel>Administrative Panel>Services>Sql Server(Sql Express))
and you will Definitely get rid from this error.

Login failed for user 'NT AUTHORITY\SYSTEM'. Reason: Failed to open the explicitly specified database

I have an application that access a database frequently for a number of functions. It was running fine for several days. I received a System.Data.SqlClient.SqlException exception this morning. The application wasn't doing anything out of the regular when this happened. Any Ideas on what caused this or how to prevent it in the future?
Windows Event Log
NT AUTHORITY\SYSTEM
Reason: Failed to open the explicitly specified database.
[CLIENT: <local machine>]
Exception Stack Trace
System.Data.SqlClient.SqlException (0x80131904):
Cannot open database ""MyDB"" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\SYSTEM'.
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges()
at ***.SubmitContextChanges(DataContext dataContext, Int32 counter) in c:\Work\***.cs:line 332
Windows event right after
Attempting to load library 'xpstar.dll' into memory.
This is an informational message only. No user action is required.
This message means that it did contact the server, but could not open the database specified in the connection string (named in the exception message).
Things to check:
That the database exists on the SQL server and that it is online.
That the user has access to the specified database.
That the default database for the login is correct and that the user has access to it.
That the connection string hasn't been altered.
It turns out that one of our tables was getting too large and not flushed often enough. That the wright to database method was timing out and our retry method threw the error.
xpstar.dll did not load out of the blue. This dll hosts the extended stored procedures used by the management tools. The fact that it loaded when the incident occurred means that there was management tool activity on the server. Which leaves open many avenues on how somebody might have messed up your database, even momentarily.
Next step is to check the administrative default trace and see if you can find any activity around the time of the incident.

iis website moved to new directory and connection is disabled

i'm new to asp.net & and IIS, i'm developing a website using asp.net for learning. First i create a new blank web site using vwd and the physical directory is C:\inetpub\web1, but later i moved web1 to C:\inetpub\wwwroot and opened IIS and turn the directory to the application and try to run it using browser the error message occur,
Server Error in '/web1' Application.
Cannot open database "testdb" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\DefaultAppPool'.
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 "testdb" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\DefaultAppPool'.
Source Error:
Line 34:
Line 35: SqlConnection dbCon = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString);
Line 36: dbCon.Open();
Line 37:
Source File: c:\inetpub\wwwroot\web1\App_Code\tree.cs Line: 36
Stack Trace:
[SqlException (0x80131904): Cannot open database "test" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\DefaultAppPool'.]
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +1270
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
System.Data.SqlClient.SqlConnection.Open() +125
Node.buildTree(String contentType, String mode) in c:\inetpub\wwwroot\web1\App_Code\tree.cs:36
header.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\web1\header.aspx.cs:14
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Anyone know what is the problem?
thanks
The error looks pretty clear to me:
Login failed for user 'IIS APPPOOL\DefaultAppPool', at DbConnectionPool.GetConnection.
I suppose the site was previously in an application pool that was run by NT AUTHORITY\NETWORK SERVICE, and that user was given permissions on the database you want to use, using Integrated Security.
If this is the case, simply change the user your Application Pool runs under.

Security Exceptions while initializing Nlog event log target

I'm using NLog in my ASP.NET application hosted on IIS and Windows server 2003. When I run the code on my develop machine, everything is Okay. But when I deployed the code to the server. The initialization of NLog target will cause an security exception:
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Requested registry access is not allowed.
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:
[SecurityException: Requested registry
access is not allowed.]
System.ThrowHelper.ThrowSecurityException(ExceptionResource
resource) +51
Microsoft.Win32.RegistryKey.OpenSubKey(String
name, Boolean writable) +7462217
System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData
sourceData) +366
NLog.Targets.EventLogTarget.CreateEventSourceIfNeeded()
+637 NLog.Targets.EventLogTarget.InitializeTarget()
+40 NLog.Targets.Target.Initialize() +264
NLog.Config.LoggingConfiguration.InitializeAll()
+233
Does anyone when what should I do in order to give the application proper permission? Thanks!
Okay, I got it. Network Service account does not have permission to read/write the event log. That's why the exception thrown.
I have run my application once as administrator to create the appropriate rules in the EventLog.

Categories