Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 2nd, 2007, 09:46 AM
Authorized User
 
Join Date: Sep 2006
Location: Belgrade, Serbia, Yugoslavia.
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to VerbatimBOT Send a message via Yahoo to VerbatimBOT
Default Help with ASP.NET Membership

Hi everyone!
I'm having trouble with my SQL query.
The database scheme is http://img237.imageshack.us/img237/2484/schemahx1.gif.

The query I am trying to fix is
Code:
SELECT m.email
FROM aspnet_users u
INNER JOIN aspnet_usersInRoles uir ON u.userId = uir.userID
RIGHT OUTER JOIN aspnet_membership m ON u.userID = m.userID
INNER JOIN aspnet_custom_registrants cr ON m.userID = cr.userID
LEFT OUTER JOIN aspnet_roles r ON r.roleID = uir.roleID
WHERE cr.receiveNewsletter = 1
/* if I add this line of query, I get no results at all
AND r.roleName = 'user' */
I believe you all noticed what I'm trying to do. I need a list of emails of users in a specific role who are subscribed for newsletter.

Thank you in advance!
Aleksandar

__________________
Aleksandar Dragosavac
Belgrade, Serbia
Reply With Quote
  #2 (permalink)  
Old May 2nd, 2007, 09:56 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Try this instead:

SELECT m.email
FROM aspnet_users u
INNER JOIN aspnet_usersInRoles uir ON u.userId = uir.userID
RIGHT OUTER JOIN aspnet_membership m ON u.userID = m.userID
INNER JOIN aspnet_custom_registrants cr ON m.userID = cr.userID
LEFT OUTER JOIN aspnet_roles r ON r.roleID = uir.roleID AND r.roleName = 'user'
WHERE cr.receiveNewsletter = 1


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #3 (permalink)  
Old May 2nd, 2007, 10:04 AM
Authorized User
 
Join Date: Sep 2006
Location: Belgrade, Serbia, Yugoslavia.
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to VerbatimBOT Send a message via Yahoo to VerbatimBOT
Default

That didn't help.
Why did you put "AND r.roleName = 'user'" near the "LEFT OUTER JOIN aspnet_roles r ON r.roleID = uir.roleID"?
Shouldn't this be a simple INNER JOIN query?

Reply With Quote
  #4 (permalink)  
Old May 2nd, 2007, 10:20 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I have had problems with querys where I place a field from a joined table in my WHERE clause and fixed the problem by making it one of my join parameters, was not sure if you were having the same problem.

In any case if the statement returns a result set without: AND r.roleName = 'user' then i am going to bet that the column does not contain just 'user'

What happens if you query that table with a simple select:

SELECT * from aspnet_roles where roleName = 'user'

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #5 (permalink)  
Old May 2nd, 2007, 11:14 AM
Authorized User
 
Join Date: Sep 2006
Location: Belgrade, Serbia, Yugoslavia.
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to VerbatimBOT Send a message via Yahoo to VerbatimBOT
Default

Code:
SELECT * from aspnet_roles where roleName = 'user'
returns expected results of 1 row.
I don't know if you have some experience with asp.net membership tables, but here's how it works: when you create a membership user, the aspnet_users table contains 2 rows for each user. One record is related to the record from the aspnet_membership table, and the other one is related to aspnet_usersInRoles.
I suppose this is where the problem begins.

Reply With Quote
  #6 (permalink)  
Old May 2nd, 2007, 01:16 PM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
quote:Originally posted by VerbatimBOT
but here's how it works: when you create a membership user, the aspnet_users table contains 2 rows for each user. One record is related to the record from the aspnet_membership table, and the other one is related to aspnet_usersInRoles.
I hate to spoil the fun, but this is *not* how it works.

When you create a user and add it to a role, you get the following records:

aspnet_Users
1 record that contains the base user data used by all providers. User ID for example: 27fea12d-a12d-4463-a3f6-d0491aca1316

aspnet_Membership
1 record, with all the Membership data for a user.
User ID is the same as in the _Users table as it is in fact a reference: 27fea12d-a12d-4463-a3f6-d0491aca1316

aspnet_UsersInRoles
1 record: a link between a RoleID (for example 43861e10-4666-474d-ab11-700c95e536bf) and the User's ID from the aspnet_Users table (27fea12d-a12d-4463-a3f6-d0491aca1316)

If you're seeing something else, something is seriously wrong.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #7 (permalink)  
Old May 2nd, 2007, 01:58 PM
Authorized User
 
Join Date: Sep 2006
Location: Belgrade, Serbia, Yugoslavia.
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to VerbatimBOT Send a message via Yahoo to VerbatimBOT
Default

Yes, I just found out that my membership and role provider definitions were wrong. I made a small roleProvider correction in web.config and everything works perfect now.
The only strange thing is that when I started implementing custom membership and role providers, I've noticed from the start that I always get 2 records in my aspnet_users table. Normally, I asked around about the issue, and never got the answer about it. So, I started to believe that's normal! :)
I wanna thank YOU and dparsons for helping me.

Cheers! :)

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
ASP.NET Membership and ActiveDirectory Quick209 ASP.NET 2.0 Professional 0 June 13th, 2007 12:41 PM
ASP.NET SQL Membership Provider bignermo ASP.NET 2.0 Professional 2 March 20th, 2007 05:41 AM
Roles and membership asp.net 2 zeeshannasir ASP.NET 1.x and 2.0 Application Design 1 September 22nd, 2006 03:34 AM
Roles and membership asp.net 2 zeeshannasir ASP.NET 2.0 Basics 2 September 15th, 2006 07:24 AM
asp.net 2 custom membership provider andyw ASP.NET 2.0 Professional 24 September 6th, 2006 08:31 AM



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


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