0

This is my code :

DataClassesDataContext data = new DataClassesDataContext();
var hey = from p in data.Provas
          select p;
Response.Write(hey.First().title_it);

if I open this playing start to Visual Studio, it opens http://localhost:51180/Website1/ and I get the value taken from DB.

But, if I open the website with http://localhost:8080/ (which usually I open with this) I get :

System.Data.SqlClient.SqlException: Cannot open database "Website1" requested by the login. The login failed.

Login failed for user 'IIS APPPOOL\Website1'.

How can I should settings? IIS problem?

markzzz
  • 47,390
  • 120
  • 299
  • 507

2 Answers2

3

As @usr pointed out the answer is in front of you.

When you run the app in debug mode form Visual Studio the user connecting to the database is the user logged into the PC and running Visual Studio - the odd are that this user (you!) is an administrator and has administrator rights with SQL Server (I'm assuming a local instance).

When you run the app via the local installation of IIS (which it is reasonable to assume is the full version, not express) then, unless you change the app pool for the application, it will be running as a local system user (right now I forget which one, you can go look at the app pool to see) and by default that user will not have access to the databases in SQL Server.

To fix this you need to do one of two things either: a) Change the user in the app pool to one that has rights to the database in SQL Server (if you want good practice then you should define an explicit user) b) Grant the appropriate rights to the appropriate system account to access the database

(Note that in both cases you're going to need to add the user to SQL Server using Management Studio or equivalent)

Murph
  • 9,985
  • 2
  • 26
  • 41
  • I think I need to change that app pool connection string. I see it on web.config, right? Actual is `` : how can I change it? – markzzz Apr 01 '12 at 15:51
  • Solved, changing LocalSystem in the advanced option on app pool, following this http://stackoverflow.com/questions/7698286/login-failed-for-user-iis-apppool-asp-net-v4-0 – markzzz Apr 01 '12 at 16:01
  • What do you think about? I was lucky? :) – markzzz Apr 01 '12 at 16:01
1

Verify login names on http://localhost:8080/. Possibly this article will help you.

Community
  • 1
  • 1
Valeriy Gorbatikov
  • 3,459
  • 1
  • 15
  • 9