MVC DataReader超时错误

时间:2016-02-23 18:02:48

标签: c# sql-server

我有错误超时的这个问题,总是当它假设从数据库获取数据它反弹错误。我正在尝试使用以下代码从数据库中检索视频:

Repository.cs

public List<videoTble> Video()
{
        var model = new List<videoTble>();

        string ConStr = "Data Source="";Connect Timeout=60";

        using (SqlConnection con = new SqlConnection(ConStr))
        {
            string str = "SELECT * FROM videoTbles";
            con.Open();
            SqlCommand cmd = new SqlCommand(str, con);
            cmd.CommandTimeout = 60;
            SqlDataReader rd = cmd.ExecuteReader();

            while (rd.Read())
            {
                var v = new videoTble();
                v.Name = rd["Name"].ToString();
                v.Data = (byte[])rd["Data"];
                v.ContentType = rd["ContentType"].ToString();
                v.ArtistName = rd["ArtistName"].ToString();
                v.Expirydate = (DateTime)rd["Expirydate"];

                model.Add(v);
            }
            con.Close();
        }
        return model;
    }

Controller.cs

public ActionResult Download()
{
        Repository res = new Repository();

        ViewBag.Video = res.Video();
        return View();        
}

Model.cs

public partial class videoTble
{
    [Key]
    public int Id { get; set; }
    public string Name { get; set; }
    public string ContentType { get; set; }
    public byte[] Data { get; set; }
    public string ArtistName { get; set; }
    public DateTime Expirydate { get; set; }
}

The timeout Error I got, when i run application

1 个答案:

答案 0 :(得分:0)

您似乎将视频作为原始数据存储在数据库中。我强烈建议不要这样做。将视频文件存储在文件系统中,并将路径存储到数据库中的视频文件中。