ASP.NET web service does not connect with database in IIS7 - asp.net

When I try to publish my asp.net web service application on IIS7, my application works perfect when debugging with Visual Studio. But, when I try to access my webservice from IIS by typing on browser: http://localhost:port/Service1.asmx and click on the method and then click "Invoke" it gives me this error:
System.Data.SqlClient.SqlException: The SELECT permission was denied on the object 'Marimi', database 'eMagazin', schema 'dbo'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader()
at WebService.Service1.GetMarime() in C:\Users\Eduard\Desktop\MaG_beta01\MaG\WebService\Service1.asmx.cs:line 741
My Connection to database in web.Config is :
<connectionStrings>
<add name="connection" connectionString="Data Source=EDUARD-PC\EDD;Initial Catalog=eMag; Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
and I use as Application Pool the ASP.NET v4.0 Classic
I've searched for the solutions on google but I haven't found anything helpful....
Thank you all in advance...

The Application Pool Identity has no permissions on your database: either do not use integrated security, or create a dedicated user for the appool who has database permissions.

Related

how to solve the Inedo Hub Proget installation error?

i am trying to install proget on my 2012 server,
i am getting these error, this might be due to error in configuration
Please let me know the integration url and feed url..
Product: ProGet
Version: 5.1.15
System.Data.SqlClient.SqlException (0x80131904): Invalid object name 'Configuration'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteScalar()
at Inedo.Hub.Data.InstalledProduct.g__readDbConfigValue|59_0(String key, <>c__DisplayClass59_0& ) in C:\InedoAgent\BuildMasterTemp\Temp_E80991\Src\src\InedoHubCore\Data\InstalledProduct.cs:line 161
at Inedo.Hub.Data.InstalledProduct.ScrapeFromInstallation(String targetPath) in C:\InedoAgent\BuildMasterTemp\Temp_E80991\Src\src\InedoHubCore\Data\InstalledProduct.cs:line 151
ClientConnectionId:674594c1-dcf5-4bac-9fec-44a7a4756ba3
Error Number:208,State:1,Class:16
The integration URL in the Inedo Hub [config] should be https://my.inedo.com/services/v1.
To change the port ProGet listens on, use the Configuration tab after installing.
If ProGet was not previously successfully installed on this machine, deleting the file at %ProgramData%\Inedo\SharedConfig\ProGet.config will stop Inedo Hub from trying to read data from the database.

No write permission to SQL database tables from IIS application, despite having application pool setup in SSMS with correct permissions

I have a .NET application developed in Visual Studio 2017 deployed to an IIS (version 7.5) server that is now receiving the below error after I published to production, after a year of working just fine:
The UPDATE permission was denied on the object '[table name]', database '[database name]', schema 'dbo'.
The only change made to the application was updating an HTML link in an .aspx page.
In IIS I have created a custom application pool with the following settings:
Name: Safety App Pool
.NET Framework: v4.0
Managed Pipeline Mode: Integrated
Identity: ApplicationPoolIdentity
In SQL Server, I have setup a security login for IIS APPPOOL\Safety App Pool, and I have added this to the users of the database, and explicitly granted permissions on the database to this user to Connect, Delete, Execute, Insert, Select, and Update. Remember, this setup worked fine just one week ago. I published last Wednesday before going on annual leave for a few days (of course), and come back to find people are unable to make updates or inserts from the website.
What is really strange is that even if I change the application pool to a different one that is still currently working and able to update/insert to the same database, I still get the error that this specific application cannot. This is why I think there is some setting in either the web.config file, or something that Visual Studio did specifically during publishing that is causing the problem. However, I made no changes to any of the configuration/publishing files before pushing to production last week. I have copied and pasted the error as it shows up in the Application Event Log:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 7/18/2018 10:24:43 AM
Event time (UTC): 7/18/2018 3:24:43 PM
Event ID: 81f28c8d624b48f2a02c489663556877
Event sequence: 42
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1/ROOT/Safety-2-131764005145890618
Trust level: Full
Application Virtual Path: /Safety
Application Path: D:\wwwroot\Safety\
Machine name: IGSKIACWVMGS011
Process information:
Process ID: 6600
Process name: w3wp.exe
Account name: IIS APPPOOL\Safety App Pool
Exception information:
Exception type: SqlException
Exception message: The UPDATE permission was denied on the object 'SHA_Site_Servicing', database 'simsdb', schema 'dbo'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicUpdate(TrackedObject item)
at System.Data.Linq.ChangeDirector.StandardChangeDirector.Update(TrackedObject item)
at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at Safety.SHAEdit.ibHazard_Command(Object sender, CommandEventArgs e) in D:\gitrepos\sims\Safety\SHAEdit.aspx.cs:line 482
at System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Request information:
Request URL: http://sims.water.usgs.gov/Safety/SHAEdit.aspx?site_id=3000336
Request path: /Safety/SHAEdit.aspx
User host address: 136.177.160.25
User: GS\dterry
Is authenticated: True
Authentication Type: Negotiate
Thread account name: IIS APPPOOL\Safety App Pool
Thread information:
Thread ID: 57
Thread account name: IIS APPPOOL\Safety App Pool
Is impersonating: False
Stack trace: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicUpdate(TrackedObject item)
at System.Data.Linq.ChangeDirector.StandardChangeDirector.Update(TrackedObject item)
at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at Safety.SHAEdit.ibHazard_Command(Object sender, CommandEventArgs e) in D:\gitrepos\sims\Safety\SHAEdit.aspx.cs:line 482
at System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Try deleting
Trusted_Connection=True;
or
Integrated Security=True;
from your connection string.

Windows Service SQL timeout exception

I have a Windows service which continuously each 10 seconds queries the SQL Server database table, and I also have a web site which also queries the same database table after 25 seconds.
After some time I get exception - server timeout exception has occurred. I went through stack-overflow site and has done the changes to SQL configuration settings but still I got the same exception. What to do?
Stack Trace
at System.Data.SqlClient.SqlConnection.OnError(SqlException
exception, Boolean breakConnection) at
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData() at
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,
RunBehavior runBehavior, String resetOptionsString) at
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
async) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method, DbAsyncResult result) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method) at
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
behavior, String method) at
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior
behavior) at
System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at
Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteReader(DbCommand
command, CommandBehavior cmdBehavior) at
Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteReader(DbCommand
command) at
Microsoft.Practices.EnterpriseLibrary.Data.CommandAccessor1.<Execute>d__0.MoveNext()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at System.Runtime.Remoting.Messaging.Message.Dispatch(Object target, Boolean fExecuteInContext) at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage
msg, Int32 methodPtr, Boolean fExecuteInContext)
Show me the code! timeout exception usually are because you don't close the database connection.
try add the code in the final of algorithm
if (connection.State == System.Data.ConnectionState.Open)
{
connection.Close();
connection.Dispose();
}
If you use to EnterpriseLibrary, try add more time to commandTimeOut
DbCommand dbcommand = database.GetStoredProcCommand("usp_TheStoredProcedureName");
dbcommand.CommandTimeout = 120;

Error on IIS for ASP.Net Application

I am facing this error occasionally. When I restart the IIS this problem is resolved. The web server(IIS) has more than 10 sites hosted, so i can't restart it simultaneously.
System.Data.SqlClient.SqlException: Distributed transaction completed. Either enlist
this session in a new transaction or the NULL transaction. at
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean
breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler,
SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() at
System.Data.SqlClient.SqlDataReader.get_MetaData() at
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior
runBehavior, String resetOptionsString) at
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,
RunBehavior runBehavior, Boolean returnStream, Boolean async) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior
runBehavior, Boolean returnStream, String method, DbAsyncResult result) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior
runBehavior, Boolean returnStream, String method) at
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at
System.Data.SqlClient.SqlCommand.ExecuteReader() at MyLibrary.LoadDDList(DropDownList&
curDDL, String strTextField, String strValueField, String strTable, String svarconditional)
Please help me find a solution which preferably doesn't involve restarting IIS.
You have a function called LoadDDList in the MyLibrary class.
This function needs a Try Catch around the ExecuteReader() command.
Try
mySqlCommand.ExecuteReader()
Catch sqlException As SqlClient.SqlException
If sqlException.ErrorCode >= 10 Then
Throw
End If
End Try
In the catch, you want to check for an ErrorCode less than 10. If it's less than 10, then it's just a warning message and you can ignore it. If it's 10 or greater, you need to rethrow it, since it's an actual SQL error (parsing error, invalid table, etc.).
Looking at your stack, this is just a warning and should be ignored. You need to fix your code so you won't crash IIS when you hit this SQL Warning.

Suspect malicious probing in my asp.net ecommerce app

I am receiving repeated errors from my asp.net ecommerce web app. I am beginning to suspect an automated malicious probe as this is the twelfth attempt to access ProductId=69 which does not exist (ProductId 69 was removed month ago ). I have not found any info via google and hope someone recognizes this. Here is the log entry.
Page location:
/Product.aspx?ProductId=69
Message: Violation of PRIMARY KEY
constraint 'PK_ShoppingCart'. Cannot
insert duplicate key in object
'dbo.ShoppingCart'. The statement has
been terminated.
Source: .Net SqlClient Data Provider
Method: Void
OnError(System.Data.SqlClient.SqlException,
Boolean)
Stack Trace:
at
System.Data.SqlClient.SqlConnection.OnError(SqlException
exception, Boolean breakConnection) at
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj) at
System.Data.SqlClient.TdsParser.Run(RunBehavior
runBehavior, SqlCommand cmdHandler,
SqlDataReader dataStream,
BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject
stateObj) at
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader
ds, RunBehavior runBehavior, String
resetOptionsString) at
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior,
Boolean returnStream, Boolean async)
at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior,
Boolean returnStream, String method,
DbAsyncResult result) at
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
result, String methodName, Boolean
sendToPipe) at
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at
GenericDataAccess.ExecuteNonQuery(DbCommand
command)
After much observation I conclude that these page requests are bots, probably search engines.
Finally identified this error as a duplicate order attempt.

Resources