none
Can anyone see what's wrong with this query? RRS feed

  • Question

  • Hi Folks,

    I'm sorry for what is likely a stupid question but... I'm a very new aspiring developer and in my project I added two tables and a domain service etc from the ASP Membership provider.  My task at this point is that I'm trying to retrieve a matched email given the user inputting their user name (this is the first part of my effort at building my own password recovery page).  Any way, running debug shows me that the input text is fine, and looking at the table that's referenced I see the user name exactly as it appears in the parameter but it returns no result :S I hope I'm explaining this well...

    My code is as follows:

     

    private void submitInfoBtn_Click(object sender, System.Windows.RoutedEventArgs e)

    {

     

    string retrieveName = enterUserNameBox.Text;

     

    MemberInfoDomainContext dc = new MemberInfoDomainContext();

     

    aspnet_User inquiry = dc.aspnet_Users.Single(p => p.UserName==retrieveName);

     

    aspnet_Membership email = dc.aspnet_Memberships.Single(p=>p.UserId==inquiry.UserId);

     

    MessageBox.Show (email.Password);

     

    }

    Thanks very much for any insight and suggestions!

    Paul
    Thursday, March 4, 2010 10:02 PM

Answers

All replies

  • Is there possible case situation or extra spaces either in the inputted text or the text in the database which would not make the connection?
    William Wegerson (www.OmegaCoder.Com)
    Thursday, March 4, 2010 10:27 PM
    Moderator
  • Thanks for the reply William,

    I really don't think those are issues. Viewing the string in debug, it reads correct and matches the name field in the db precisely. I even tried typing in a known user name as a string literal rather than using the variable, and tried multiple known user names from the ASP db.  It should work, shouldn't it?

    Good thing I have no hair or I'd be tearing it out...
    Thursday, March 4, 2010 10:30 PM
  • Is the Database Context using the right database? The constructor parameter can be used from the default one setup in the config. I override that and pass in a specific connection string for each instance Dev/Test/UAT/Production as needed. Is your default one wrong for what you think it should be?
    William Wegerson (www.OmegaCoder.Com)
    Thursday, March 4, 2010 10:34 PM
    Moderator
  • Well, to be candid this stetches my meager noob understanding but I sure don't see anything wrong, and I have no problem accessing the db to create a new user, log on, etc as well as other authentication functions so I'm truly stumped.  But I feel a little better knowing someone much more experienced is at least a little puzzled ;)

    Thanks once again for yout time, I'd be grateful if anything occurs to you!

    Paul
    Friday, March 5, 2010 1:22 AM
  • What I mean is that the constructor takes a connection string to the database. When one first creates the linq entites by dragging from the database to the dbml file, it puts a *that* connection string in the config file. You could be thinking you are targetting one database while the code is looking at another.

    Have you looked at linqpad and done the same query?
    William Wegerson (www.OmegaCoder.Com)
    Friday, March 5, 2010 2:17 AM
    Moderator
  • Thanks William,

    I downloaded Linqpad but it's going to take me a bit to figure out how to configure and use it :S  I'll do my best and let you know if I find anything from it...

    Guess this is all part of the learning curve ;)
    Friday, March 5, 2010 2:38 AM
  • Well, OK... I tried figuring out LinqPad but frankly it's a bit beyond me really.  I can get it to connect to the db fine but that's really as far as I get.  My assumption at this point since I can log in and out and pop up message boxes with user name, etc is that my connection string is fine unless you think that's not a valid assumption?  I'm in over my "pay grade" and struggling to figure out what to try next...
    Friday, March 5, 2010 5:43 PM
  • I think the issue is that you are using RIA Services and you're trying to query from Silverlight. In Silverlight, you can't query a database directly, but RIA services does make it appear so that you can do this. I think that's where the confusion lies. In this scenario, you'll need to add a method to the domain service on your web site e.g.

    public string GetEmailByUserName(string userName)

    {

        // Do query here and return the name

        return ...;

    }

     

    When RIA services sees this method it will generate another method on your MemberInfoDomainContext called GetEmailByUserName. However, note that all operations that talk with a web service are asynchronous so you will not get the response right away. Because of this you'll need to provide a callback function that can read the result. For example:

     

    context.GetEmailByUserName("foobar", op => MessageBox.Show(op.Value), null);

     

    Let me know if I can be of any more help.

     

    David


    Blog - http://blogs.rev-net.com/ddewinter/ Twitter - @ddewinter
    Friday, March 5, 2010 6:20 PM
    Answerer
  • Hmmmmmmm... I bet you're right David as that makes sense in a perverse drive me insane sort of way ;)

    I have a very slight grasp of what you're describing and I'll try to do it and let you know (if) how I make out... if you hear shrieking it will be me ;)

    Thanks, and I'll be in touch no doubt!

    Paul
    Friday, March 5, 2010 6:36 PM
  • OK David... I hope I'm not wearing out my welcome... please don't give up on me yet.  I only partially follow this, but I'm trying hard.  I wrote the following method in my domain service:

     

    public IQueryable<aspnet_User> GetUserViaName(string enterUserNameBox)

    {

     

    IQueryable<aspnet_User> query = from n in DataContext.aspnet_Users

     

    where n.UserName == enterUserNameBox

     

    select n;

     

    return query;

    }

    And frankly I didn't know how to get the information I need back out but I called it just to watch it in debug as follows:

     

    private void submitInfoBtn_Click(object sender, System.Windows.RoutedEventArgs e)

    {

     

    string retrieveName = enterUserNameBox.Text;

     

    MemberInfoDomainContext dc = new MemberInfoDomainContext();

    dc.GetUserViaNameQuery(retrieveName);

     

    }

     When I tried incorporating the callback function you mentioned I got a warning that no overloads called for 3 arguments, etc.

    And in debug I still see that "enumeration yielded no result" or words to that effect.  Am I back to square one?

    I really appreciate any help, as you can tell I'm very new at this but working my butt off trying to get up to speed.

    Friday, March 5, 2010 7:41 PM
  • Hi Paul,

     

    Glad to see you again!

     

    I agree with David that the problem could be at the RIA services side. 

     

    If it is convenient for you, could you send me a demo project and db file to reproduce this problem?   I will do my best to help.   My mail address is v-micsun@microsoft.com.  Thanks a lot!

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, March 9, 2010 7:13 AM
    Moderator
  • Hi Paul,


    How is the problem?   Please feel free to tell me if you need any further assistance.
     

    Have a nice weekend!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by PaulBinCT Friday, March 12, 2010 2:23 PM
    Friday, March 12, 2010 1:19 AM
    Moderator
  • Hi Lingzhi!

    As always, I'm grateful for your personal interest!  I'm sorry I didn't reply sooner, for some reason I wasn't getting notices that there were posts.  Anyway, I've gotten it working with the help of forum members of course ;)  It was evidentally mainly an issue of not properly doing a callback, or at least that's my noob understanding... but I got it working.  Now on to the next problem, and the next ;)

    Thank you again... I appreciate your interest and help.  Hope you have a good weekend!

    Paul
    Friday, March 12, 2010 2:23 PM
  • Hi Paul,

     


    It's great to hear that the problem is solved.   :)


    Have a nice day!
     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, March 16, 2010 1:12 AM
    Moderator