Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 2nd, 2006, 06:18 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Imar,

Well---Yeah...Netherlands. I've never made it past Seattle...

:)

Your last message explains alot. I did accidentally just copy both strings...the difference was the Integrated Security. It said SSPI, I changed it to TRUE..then it worked. What did that do?

I do have commercial version that has both....so, what you're saying is that I could attach the aspnetdb.mdf to it and then change the connection string to it's path? If so, I assume I would need a full path-not the |Data Directory| ?

What got me is that I didn't really have to do any manipulation that last time (other than the SSPI thing because it saw aspnetdb.mdf as being there--even though I had detached and deleted. If I used commercial SQLSERVER--I assume I would have to create the ASPNET user as a Windows auth. user---I didn't have to do any of that with EXPRESS this last time.

Thank you again sir---that should about do it.
Kind Regards,
Rob

 
Old August 2nd, 2006, 07:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, almost.

When you use the Express Edition, you can use the AutoAttach feature, using the DataDirectory. The latter option is optional but makes it easier to reference the App_Data path.

When you attach a database to the full version of SQL Server, you don't use the AutoAttach feature and you don't reference the MDF in a path. So, you don't use a path and you don't use DataDirectory. All you do is reference the database name (initial catalog) in the connectionstring, like this:

Data Source=Server;Initial Catalog=Database;Integrated Security=SSPI;

So, there's nothing to attach at run-time, because you already attached the database to SQL Server. No need for paths in the connection string in that case.

With the Express Edition, you don't need to explicitly add the security account to the database, because the whole SQL Server Express runs in the context of the caller. However, when you use the full version of SQL, you do need to add the proper account (like ASPNET) to SQL Server and give it the necessary permissions to the database you attached manually.

Re: Integrated Security and SSPI. Below you find two equivalent connection strings:

Data Source=Server;Initial Catalog=Database;Integrated Security=SSPI;
Server=Server;Database=Database;Trusted_Connection =True;

Both "Integrated Security=SSPI" and "Trusted_Connection=True" mean the same and are aliases for each other. I don't think other combinations (e.g. Trusted_Connection=SSPI) will work.

Does this help?

Imar
 
Old August 2nd, 2006, 09:22 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Tremendously---however, it doesn't explain why ... well....when I deleted everything to try again, I had actually attached the aspnetdb.mdf DB to EXPRESS...when I had done that (and changing nothing else) I was getting the error that /Localhost/ASPNET couldn't open the EXPRESS DB. So---I can't explain that.

The only other thing I cannot explain is why, when I detached the above, deleted the app_data folder with everything in it...and created a new website in V Studio...when I went to run it...as soon as I attempted to login...I got an error saying that aspnetdb.mdf was busy or already existed...almost as if I didn't delete it entirely. However, when I changed the value of integrated security from SSPI to TRUE..it worked. I have no idea why.

Aside from those two "unexplainables" I feel much better about everything.

Kind Regards,
Rob

 
Old August 3rd, 2006, 01:58 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Imar,

Sorry---any way you could comment on just my last two abnormalities in above?

Regards,
Rob

 
Old August 3rd, 2006, 04:25 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hard for me to explain either. Like you said earlier, you changed "tons of settings" so who knows what you changed at what point.

I know that quite often the *first* time you load a database, it fails because it takes a long time to attach the database. Subsequent requests succeed because the database has already been attached. Maybe this is what you saw: a first time failure, with a change that didn't actually change anything...

But again, hard for me to say on a distance, without knowing *exactly* what you did or changed.

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: Wasting My Hate by Metallica (Track 10 from the album: Load) What's This?
 
Old August 3rd, 2006, 08:30 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Ok..how about this then. I use visual studio to create as simple two page site with default and login using login control and using the ASP.NET application tool. I create a user etc..just fine. I save the site in my default web site and type localhost and it runs just fine.

Then, I create new directory called "robtry" and create a new virtual directory under default. I copy/paste the files from main site into my robtry directory (this includes the app_data folder and the aspnetdb.mdf and .ldf files). I restart the computer (Keep in mind I am doing this just to learn they behavior of how ASP talks to SQLSERVEREXPRESS).

NOW I try typing /localhost/robtry and put in my user name and get the message that it failed. When I try debuggin in Visual Studio--I get a more explicit message---"Login failed for user LOCALHOST\User Name (where user name is my windows log in--Robert Searing). I then try localhost again..and it works just fine.

Somehow, it appears that my aspnedb.mdf file is being bound by the first try...but you had stated that |Datadirectory|aspnetdb.mdf would point to the app_data folder in the current directory--thus robtry/app_data.

Why do I get a login failure when trying to access the copy?

Kind Regards,
Rob

 
Old August 4th, 2006, 06:29 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

While I can't be sure because you changed a lot of stuff, I think this is a permissions issue.

The account that the web server runs under needs permissions to the App_Data folder. When you run from within VWD, that account is you.

When you browse to the site through IIS, that account is the ASPNET account. Maybe this account already has permissions to the App_Data folder of localhost, but not to the folder robtry/App_Data?

Imar
 
Old August 4th, 2006, 08:05 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Sounds logical--but when I try typing http:\\localhost\robtry (of course, outside of VS) I am getting a message saying it failed--but it doesn't give me a detailed error--simply says "it failed"...in text below the password box. It's when I do it in VS that I get the detailed error showing user localhost/rsearing couldn't log in.

Also--the more i think about it...when I have tested the default directory in VS -- it worked just fine. Again, here is detail of what I did:

1) Used VS to create web site in default directory in IIS. THis site contained simple login.
2) Tested it--both inside VS and in IIS--worked just fine.
3) Created new directory in IIS called robtry and simply "copied" the aspx pages, the app_data folder with .mdf contents and web.config file to the robtry directory
4) When I try this it won't work......

Imar--I swear--I'll stop at this point and won't continue this long thread---the main purpose of it was to understand how asp integrates it's aspnetdb.mdf file with sql server...it just confuses me with the various things that occur.

Kind Regards,
Rob

 
Old August 4th, 2006, 08:52 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:but it doesn't give me a detailed error--simply says "it failed"...in text below the password box. It's when I do it in VS that I get the detailed error showing user localhost/rsearing couldn't log in.
I think this makes sense.

I'll try to describe how authentication works, and then it's up to you to determine whether this applies in your situation.

When you get a real error, it means the web server account has no permission to access the database. This is a technical error; hence you get a nasty error page / message. When you get the error from within VWD (I assume you use the built-in web server which by default runs under your account) it probably means that your own account doesn't have the necessary permissions to the database.

However, if you get a nice, red error message indicating something like "Login failed, please try again", it means you get a functional error. The web server is able to access the database, but it could not find the appropriate user account / password combination.

There's an interesting reason behind the different behavior you are seeing when you browse to the site as http://localhost or http://localhost/SomeSite.

This reason is the applicationName. Normally, when you override your own provider settings in the web.config, you can set the applicationName. However, the default settings for membership and roles for the machine have a name of /. If you override the membership settings and don't provide an applicationName, one is generated at run-time. You can see the applications in the aspnet_Applications table in the database.

For a site at http://localhost, the app is called "/". For a site at http://localhost/SomeSite the app can end up as SomeSite.

How does this influence you? you may ask. Users in the database are connected to applications. So, let's say the user Rob is connected to the app /. When you log in to http://localhost everything works fine. However, when you browse to http://localhost/SomeSite then login will fail, because Rob is not connected to the SomeSite application.

A blog by Scott Guthrie has more details about this:
http://weblogs.asp.net/scottgu/archi...Providers.aspx

In short: define the applicationName in the membership and role providers so you explicitly define what application you're working with...

Does this clarify the behavior you are seeing?

Cheers,

Imar
 
Old August 4th, 2006, 10:33 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Ok..that makes perfect sense as to why I get the "nice red error"...but I still am a little confused on why I get a localhost/Robert Searing couldn't access when trying it in Vis Studio....as I have tried using Visual Studio for debugging the localhost site and it worked fine ----- Why would it be using a different login.

Let met put it this way...If I am building this in Vis Studio--and debuggin--I am assuming it would use the Robert Searing login? At the same time, I can pull up a web browser and get to the site just fine...is this using the aspnet login?

I can play with this---if I need to add permissions, however, I assume, since this is using SQLEXPRESS and it is not attached, I would need to attach..then add logins..etc...

I'll play with this when I get back home.

Imar---sheesh---I really want to thank you. I really wish there was a book that helped explain these intricacies.


I'm actually using full blown Visual Studio, not VWD...although I assume they both use the same built in web server.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about ASPNETDB.MDF frankym BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 October 3rd, 2008 11:26 AM
Problem connecting to ASPNETDB.MDF file nikitos1979 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 April 24th, 2008 09:55 AM
ASPNET account for ASPNET.MDF DB-Please help rsearing ASP.NET 2.0 Basics 13 November 6th, 2007 11:54 PM
Get password value from aspnetdb.mdf rsearing ASP.NET 2.0 Basics 8 October 12th, 2007 09:12 AM
aspnetdb.mdf Jackxxx ASP.NET 2.0 Basics 0 January 9th, 2007 01:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.