Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 23rd, 2006, 05:51 PM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cannot open database...The login failed

Visual Studio 2005
.NET 2.0
SQL Server Express

I've created a localhost web site with a database named DateTracker. When I test in Visual Studio, everything works fine. But when I open a browser and type:

http://localhost/test/Default.aspx

...I get an error:

Cannot open database "DateTracker" requested by the login. The login failed. Login failed for user 'P4\IUSR_P4'.

The name of the computer is P4.

I assume this is a permissions problem, but after spending a couple hours Googling for a solution, I've gotten nowhere.

A little help?

Rob
Reply With Quote
  #2 (permalink)  
Old May 25th, 2006, 10:16 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

did you create the project as a "file system" or "HTTP" project? By default it is a "file system" project.

Reply With Quote
  #3 (permalink)  
Old May 30th, 2006, 10:23 AM
Registered User
 
Join Date: May 2005
Location: kano, kano, Nigeria.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need to set uo the user id= and password= respectively

Reply With Quote
  #4 (permalink)  
Old May 30th, 2006, 11:49 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Which kind of authentication your datasource is? Windows and SQL or windows only?

Reply With Quote
  #5 (permalink)  
Old June 2nd, 2006, 02:59 PM
Registered User
 
Join Date: Jun 2005
Location: , New York, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please paste your connection string from config file...

Thanks,

Sr. Systems Analyst
New York, USA

http://www.geekinterview.com
http://www.exforsys.com
Reply With Quote
  #6 (permalink)  
Old June 4th, 2006, 11:22 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First, thanks to everyone for responding. I didn't realize anyone had replied to my post - I had clicked the "Check here to subscribe" box...

Okay, first question: "File system" or "HTTP project"?
It's an HTTP project.

Second: "You need to set uo the user id= and password= respectively"
That could be it, but I don't know where to set these particular items (Windows Control Panels -> Users? VS -> Website -> ASP.NET Configuration? Windows Explorer -> Security? I've been grasping at straws without any success).

Third: "Which kind of authentication your datasource is?"
It's Windows, but I'd be interesting in finding information on correctly setting up both.

Finally: "Please paste your connection string from config file..."
This is the one I've spent a lot of time messing with. I've got six connection strings in the code, five of which are commented out. Here's the most recent:

string _connString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=DateTracker;Trusted_Connection=Yes";

All six connection strings work inside VS 2005, but none of them work when I test from a browser - I get the "login failed..." error.

Thanks guys.

Rob
Reply With Quote
  #7 (permalink)  
Old June 4th, 2006, 11:59 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<Sigh> A correction. I'd like to get this right, and maybe it will help other people, so here goes...

I'm sure that I originally created this project as an HTTP project (Local IIS) - that's why I created the project in the inetpub/wwwroot/ folder. However, it looks like I may have inadvertently changed this to a "File System" project when I reopened the web site at a later date. I noticed that when I selected File > Open Web Site, VS 2005 was defaulting to "File System". Just now, I changed this setting to "Local IIS" and selected my test web site. Now when I try to test the project inside VS, I get the "login failed..." error message. Testing with the other connection strings doesn't improve things much - I get either the "login failed" error or this one:

"An error occured while establishing a connection to the server...this failure may be caused by the fact that under the default setting SQL Server does not allow remote connections."

Looks like I'm going backwards...sorry for the erroneous information in the previous post.

Rob
Reply With Quote
  #8 (permalink)  
Old June 4th, 2006, 12:53 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Rob,

10 minutes ago I finished an article called "Configuring an ASP.NET 2.0 Application to Work with Microsoft SQL Server 2000 or SQL Server 2005" that deals with configuring SQL server 2005 and your ASP.NET application. You can find the article here:

http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=395

Be sure to check out the section titled "Other Issues" near the end of the article, as it explains how to fix the "remote connections" issue.

Hope this helps and if not, please let me know so I can add additional information to the article.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Lullaby by The Cure (Track 6 from the album: Disintegration) What's This?
Reply With Quote
  #9 (permalink)  
Old June 4th, 2006, 03:37 PM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Thanks to your article, I got it working in both Visual Studio and with a browser. :D

Here's post mortem, which I hope will help other people:

Quote:
quote:Be sure to check out the section titled "Other Issues" near the end of the article, as it explains how to fix the "remote connections" issue.
This error message turned out to be a red herring; I had run into this problem before, and I had already used the SQL Server Configuration Manger to enable "Named Pipes" and TCP/IP.

The key to solving this problem was outlined in the part of your article, "Scenario 2 - Using Windows Authentication with IIS and the Database on the same Machine". I wasn't familiar with Microsoft SQL Server Management Studio, and AFAIK this app is not included with VS 2005. However, a quick Google search turned up a free beta version. As I write this in June of 2006, the app can be downloaded here:

http://www.microsoft.com/downloads/d...DisplayLang=en

Unfortunately, after following the steps in scenario 2 of your article things still weren't working, but it was easy enough to figure out the missing steps. In step 2, you specify the login name as <MachineName>\ASPNET and in step 3, you specify the "User name" as ASPNET and "Login name" as <MachineName>\ASPNET.

On my machine -- which is using a Windows login with no password (I'm the only one using it) -- I had to add my IUSR account to the SQL Server Manager. My computer is named P4, so for step 2 I specified the "Login name" as P4\IUSR_P4. And for step 3 the "User name" was IUSR_P4 and the "Login name" was P4\IUSR_P4.

Here's the connection string I'm using:

"Data Source=.\\SQLEXPRESS;Initial Catalog=DateTracker;Integrated Security=SSPI";

During the course of trying to figure this out, I came across some suggestions on various web sites to modify the Web.Config file with this line:

<identity impersonate="true"/>

This didn't work, and it doesn't seem to matter either way; if I comment this line out, everything still works.

Another suggestion was to add an <authorization><allow users> tag to Web.Config, like this (I think):

<authorization>
   <allow users="P4\IUSR_P4" />
</authorization>

Again, this didn't help, and removing it didn't hurt anything.

Whew! I never would have figured this out on my own. Thanks again, Imar.

Rob
Reply With Quote
  #10 (permalink)  
Old June 4th, 2006, 03:46 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Rob,

SQL Server Management Studio is included with the full versions of SQL Server and not with SQL Server Express Edition. However, as you found out, there's a free version available that contains most of the necessary functionality found in the commercial version.

I am a bit surprised you need the IUSR account; this account is the default Anonymous account for pre .NET web sites. However, in ,NET, the ASPNET or Network Service accounts are used. You only see IUSR when you have impersonation enabled and you are anonymous authentication.

Did you make any changes to the setup of IIS? And did you leave the impersonation element in the config file?

The <authorization> node you showed is for authentication within your ASP.NET application and has no influence in the way your app connects to SQL Server. So, leaving it out should indeed make no difference.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Intergalactic by Beastie Boys (Track 7 from the album: Hello Nasty) What's This?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Login Failed. Cant figure out why. ArnoldSanders SQL Server DTS 3 January 3rd, 2005 12:33 PM
login failed for user nt authority\anonymous login rj1406 Classic ASP Databases 1 October 24th, 2004 09:15 AM
Database login failed AcidHell2 All Other Wrox Books 0 January 2nd, 2004 02:18 PM



All times are GMT -4. The time now is 12:46 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.