Monday, March 19, 2012

Login failed

I have VS2005 Beta 2

I created a very simple Web Site that has a Login page and a Default Page

I installed MSDE so that I can use a SQL 2000 database

I ran C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\aspnet_regsql.exe
to create a database in the MSSQLSERVER for user info.

My Web.config file looks like:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=localhost;Initial Catalog=myDataBase;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="false">
<assemblies>
<add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
<authorization>
<deny users="?"></deny>
</authorization>
<authentication mode="Forms"/>
</system.web>
</configuration>


I have a Global.asax file containing:

void Application_Start(Object sender, EventArgs e) {
// always create bob and alice as users if they are not present
// so you can login and we can avoid dealing with admin
//
MembershipCreateStatus status;
if (Membership.FindUsersByName("bob").Count == 0)
Membership.CreateUser("bob", "pass@.word1", "bob@.wingtip.com", "no question", "no answer", true, out status);
if (Membership.FindUsersByName("alice").Count == 0)
Membership.CreateUser("alice", "pass@.word1", "alice@.wingtip.com", "no question", "no answer", true, out status);
}

When open the web site from the File System in VS2005 everything runs fine.

When I copy the Web site to a virtual directory set up in IIS and the open the web site using Local IIS in VS2005 I get:

Cannot open database "myDataBase" requested by the login. The login failed.
Login failed for user 'BARBARA\ASPNET'.


You use integrated security to connect to the database and when testing local in VS2005 it will use the currently logged on user running VS2005. Most likely that is your user account and it has access to the database.

The error message indicates you are trying to logon to the database with BARBARA\ASPNET user and that is the user setup to run the application in IIS. You could either change this to be another user that has access to the database needed, under directory security in IIS, or give the user BARBARA\ASPNET access to the database.|||Thanks for your reply - I don't have that much experience with this stuff -

Could you please tell me how I can go about giving BARBARA\ASPNET access to the database? I don't know about changing the user that is accessing the database in IIS. BARBARA is the name of the computer and ASPNET is the user that was created on the computer when all this stuff was loaded. Do I have to change the database server to use mixed security?

Is it a user that has to be set up for the server or for the database? In any case, I don't really know how to do this. Any direction would be appreciated.

thanks|||You might want to have a look at 3rd party tools to adminstrate MSDE.

You can do it directly in a query also.

exec sp_grantlogin 'BARBARA\ASPNET'
go
use myDataBase
go
exec sp_grantdbaccess 'BARBARA\ASPNET', 'ASPNET'
go
exec sp_addrolemember 'public', 'ASPNET'

This assumes that the group public has the proper permissions in the database. You could use dbo instead of public then the ASPNET user will be acting as database owner.

|||okay thank you very much - that gives me a direction

No comments:

Post a Comment