大家好,我一直遇到这个问题,我没有收到任何具体的错误信息。它是一个扫雷游戏项目。我可以登录,并在列表框中查看所有登录玩家的列表。效果很好。该服务的方法也可以正常工作。在调试模式下,它会将类型为“MsServer300.User”的所需对象返回给客户端的方法,并且要执行的下一行现在返回到客户端的方法中并在那里冻结。(MsServer300 是包含服务的项目的名称)。“用户”类来自连接到服务的数据库。任何想法为什么?谢谢!!这是客户端方法:(由于错误搜索原因很长)private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { /////////// try { MsServiceClient proxy = new MsServiceClient(new InstanceContext(Callback)); string s = LbConnectedPlayers.SelectedItem.ToString(); var userDetails = proxy.GetDetails(s); //<<<here is the error if (userDetails == null) MessageBox.Show("user details is null"); else LbConnectedPlayers.ItemsSource = userDetails.ToString(); }catch(Exception ex){ MessageBox.Show("error in selectionchange "+ex.Message); } }这是服务方法: public User GetDetails(string name) { try { using (ms_AvishayAndRonen6Entities ctx = new ms_AvishayAndRonen6Entities()) { //User user = ctx.Users.SingleOrDefault(a => a.UserName == name); //return user; User user = (from m in ctx.Users where m.UserName == name select m).First(); return user; } } catch (Exception ex) { User exUser = new User(); exUser.UserName = ex.Message; return exUser; } }
2 回答
慕码人2483693
TA贡献1860条经验 获得超9个赞
我没有看到连接详细信息,但我总是将多个活动结果集设置为 True。试试看,看看是否能解决你的问题。这是一个连接字符串示例:
using System.Data.SqlClient;
namespace MyConnection
{
class Connection
{
public static SqlConnection GetConnection()
{
string connectionString = "Data Source=WhateverYourdataSource;Initial Catalog=EDI;Persist Security Info=True;User ID=YourID;Password=Password.is;Integrated Security=False;MultipleActiveResultSets=True";
SqlConnection connection = new SqlConnection(connectionString);
return connection;
}
}
}
- 2 回答
- 0 关注
- 135 浏览
添加回答
举报
0/150
提交
取消