且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL/LINQ调试帮助

更新时间:2023-02-17 18:47:10

仅当查询产生无结果时,才会抛出您得到的InvalidOperationException.

The InvalidOperationException that you are getting is thrown only when the query yielded no results.

我唯一想到的是(因为您确定数据库中存在该行),所以您可能正在连接到其他数据库.

The only thing that comes to my mind, (since you say that you are sure that the row exists on the database), is that you are maybe connecting to other database.

检查您的DataContext的连接字符串,并确保查询的数据库与Management Studio中的数据库相同.

Check your DataContext's connection string and make sure you are querying the same database as in Management Studio.

顺便说一句,您正在直接查询 SqlMembershipProvider aspnet_Users表,以按UserName查找用户,您可能希望查看

BTW, you are querying directly the SqlMembershipProvider aspnet_Users table, to find users by UserName, you might want to give a look to the Membership.FindUsersByName method.