postgresql没有突然响应

时间:2014-03-19 13:26:04

标签: c# sql postgresql

我编写了一个关于通过c#从postgresql获取数据的程序。我已经运行了一个月的程序,它运行得很完美。但是,它今天突然无法运作。

这是我使用的SQL代码:

    select count(call_id) , dt,hr,mn from ( select i.call_id,a.dt,hr,mn from 
   (SELECT call_id ,to_char("event_Time" ,'yyyy-MM-dd') as dt, to_char(extract(hour 
   from "event_Time"),'FM00') as hr ,to_char(floor(extract(minute from 
   "event_Time")/30)*30,'FM00') as mn from ivr_event  where "event_Time" between 
   '2014-2-11 00:00:00' and '2014-2-11 23:59:59'  and status='playGreeting' and 
   stage='InqiryMenu'  group by dt,hr,mn,call_id) a,ivr_event i where a.call_id = 
   i.call_id  and status='getDigits'  and stage='Language' and click ='3' and 
   "event_Time" between '2014-2-11 00:00:00' and '2014-2-11 23:59:59' group by
   i.call_id,dt,hr,mn ) result group by dt,hr,mn order by dt,hr,mn

这是用于选择查询并返回arraylist的C#代码

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();

                String connstring = "Server=" + dataSource
                + ";Port=" + port + ";" + "User Id=" + userID
                + ";Password=" + password + ";Database=" + databaseName + 
                ";CommandTimeout=0;";


                NpgsqlConnection conn = new NpgsqlConnection(connstring);

                conn.Open();

                NpgsqlDataAdapter da = new NpgsqlDataAdapter(sqlStatement, conn);


                ds.Reset();
                // filling DataSet with result from NpgsqlDataAdapter
                da.Fill(ds);
                // since it C# DataSet can handle multiple tables, we will select first
                dt = ds.Tables[0];

                foreach (DataRow row in dt.Rows)
                {
                    temp = "";
                    foreach (var item in row.ItemArray)
                    {
                        temp += item + ";";
                    }

                    if (row.ItemArray.Length >= 1)
                        temp = temp.Substring(0, temp.Length - 1);

                    result.Add(temp);
                }

                conn.Close();

程序只用1个SQL在1小时内获得具有不同WHERE子句的多个计数。 然后,我循环24次以获得全天计数。

差不多一个月没问题。但是,当我今天使用相同的程序而不改变任何东西时,似乎总是等待我得到的结果。我只能通过停止postgresql服务来结束进程(我没有设置超时)。

我们得到以下例外:

System.NullReferenceException:Object reference not set to an instance.

一个非常奇怪的情况是,当我选择一个非常古老的数据时,它没关系。当我选择上周数据时,它失败了。但是,我几天前使用了相同的sql并且它有效!

对我有什么建议吗?非常感谢你!

P.S。抱歉sql已更新。这是可以运行的真正的SQL

0 个答案:

没有答案
相关问题