【发布时间】:2017-04-06 14:49:48
【问题描述】:
我正在使用 ASP.NET Web API,当我运行此方法时,我收到此错误 An error has occurred.
public List<DeviceClass> CheckDevice(string device)
{
devices = new List<DeviceClass>();
using( connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand("uspCheckDeviceID", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@sp", SqlDbType.VarChar).Value = device;
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
if(reader.HasRows)
{
if(reader.Read())
{
DeviceClass model = new DeviceClass();
model.DeviceId = reader.GetValue(0).ToString();
model.Name = reader.GetValue(1).ToString();
model.Owner = reader.GetValue(2).ToString();
devices.Add(model);
}
}
connection.Close();
}
}
}
return devices;
}
我试图确定是它的代码还是它的服务器连接。
这是我得到的存储过程的例子:
declare @sp varchar(30)
set @sp ='marksiphoneid'
exec uspCheckDeviceID @sp
我尝试从存储过程中获取结果的方式有问题吗?
错误是
加载资源失败:服务器响应状态为 500(内部服务器错误)
【问题讨论】:
-
你是要告诉我们发生了什么错误,还是我们应该使用我们的集体精神力量? :)
-
您仍然没有向我们提供来自服务器的错误。 500 Internal Server Error 意味着您需要弄清楚服务器端错误是什么。
-
我认为我无法访问该信息
-
在 VS 中
CheckDevice()方法的第一行放置一个断点。以某种方式(例如,从浏览器)点击端点,然后调试您的代码。没有人能够告诉您 500 错误的原因是什么 - 它在您的代码内部,只有您可以确定潜在的错误是什么。 -
用一个简单的try-catch块捕获异常并检查细节怎么样?
标签: c# asp.net sql-server asp.net-web-api