0

我有一个简单的 Web 服务,可以运行和查询一个简单的.mdf数据库。

我正在使用 IIS 并使其成为一个工作应用程序。

我可以从任何地方激活此 Web 服务上的每个功能。

但是当我尝试查询数据库时,我得到了这个错误:

System.Data.SqlClient.SqlException (0x80131904):无法打开登录请求的数据库“网关”。登录失败。
11-27 21:32:01.437:W/System.err(765):用​​户 'IIS APPPOOL\masn' 登录失败。

我的连接字符串是:

<add name="gatewayConnectionString" 
     connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=gateway;Integrated Security=True" 
     providerName="System.Data.SqlClient"/>

那么我怎样才能让它工作呢?更改我的连接字符串?在某处更改权限?

4

1 回答 1

1

The error says the account under which your web service is running can't access the database. In the connection string you have specified a trusted connection, so the account specified in IIS for your service's app pool will be used to log into the SQL server.

The solution is to give the app pool account (IIS APPPOOL\masn) access to the gateway database, or change the connection string to include a user name and password that has access to it, like so:

<add name="gatewayConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=gateway;User ID=someuser;Password=somepassword" providerName="System.Data.SqlClient"/>

Using a trusted connection is the better way to go, since you don't have to store a password somewhere.

于 2012-11-27T20:46:57.320 回答