Gladi
Gladi

Reputation: 425

Local db on SQLExpress error

I have a simple web service that working and queries a simple .mdf database.

I'm using IIS and making it an working application.

I can activate every function on this web service from anywhere.

But when I try to query the database I get this error:

System.Data.SqlClient.SqlException (0x80131904): Cannot open database "gateway" requested by the login. The login failed.
11-27 21:32:01.437: W/System.err(765): Login failed for user 'IIS APPPOOL\masn'.

My connection string is:

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

So how can I make it work? Change my connection string? Change permissions somewhere?

Upvotes: 0

Views: 288

Answers (1)

Chris Tybur
Chris Tybur

Reputation: 1622

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.

Upvotes: 1

Related Questions