tags:

views:

283

answers:

4

I get this using this URL (my website setup through IIS):

http://localhost/dreamrishta/Default.aspx

Cannot open database "myDB" requested by the login. The login failed. Login failed for user 'R-2C02CDE60B8C4\ASPNET'.

But when I use Visual Studios built in server: localhost:3554/Default.aspx

It works fine and does not throw any error and gets all database values correctly. Does IIS need something to be changed to make this work?

A: 

Sounds like you are trying to connect to the database via Windows authentication. Try creating a sql user and password for your database to connect. Then it should work using both methods.

Here is a sample connection string. (1.2.3.4 is the IP address or the name of the Sql Server)

"Data Source=1.2.3.4;Initial Catalog=YourDBName;Persist Security Info=False;User ID=sqluser;Password=password"

James Lawruk
Can you only connect through IIS with an sql user and password? Or can I setup IIS to accept Windows authentication too? If so is it safe to do that on my server that Rackspace host? Sorry to sound like a n00b
Yes, you can and it is safe - in fact, it is preferable, if you are allowed.
Dan Diplo
The sql user is created on the database and used to connect to the database. Is the SQL database at RackSpace along with your live Web Server?
James Lawruk
Ah... If your are using a host like rackspace then windows auth may not be possible. In this case change your connection string to use a sql user account not windows authentication.
klabranche
yes both are at rackspace, sql authentication worked! thanks
You should make Persist Security Info false.
klabranche
Good catch, klabranche. Thanks.
James Lawruk
A: 

My guess is that you are using something like "trusted_Connection=true" or "integrated Security=sspi"

The (built-in) cassini web server runs under your process, so the webserver is logging into the database as your account (probably an admin).

When you move it to IIS, it is running under the ASPNET account. Either

  1. give ASPNET limited access to the database
  2. change the identity of the Application Pool to an acceptable account.
  3. use configure the web.config to impersonate another user (http://support.microsoft.com/kb/306158)
  4. use SQL authentication to get to the DB
Rob
A: 

The built in web server uses windows authentication and it sounds like your connection string is expecting windows authentication also.

Set your IIS application to windows authentication (right click the app folder in IIS, select properties, Directory Security tab). Make sure you turn off anonymous and integrated is checked.

EDIT:

I noticed in your comment that you are using rackspace and could you do windows authentication.

If your are using a host like rackspace then windows auth may not be possible (likely isn't). In this case change your connection string to use a sql user account not windows authentication.

klabranche
A: 

When you run the Visual Studio web-server then the asp.net process runs as you (your Windows account user) and has all the permissions that you will have. When you run IIS asp.net runs as special account (usually NETWORK_SERVICE user) and, if you are using Windows Authentication for SQL Server, you will need to create an SQL Server Login for that account.

Dan Diplo