ASP.NET web service does not connect with database

2019-09-14 07:05发布

问题:

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...

回答1:

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.