当前位置: 首页>>代码示例>>C#>>正文


C# NpgsqlCommand.Cancel方法代码示例

本文整理汇总了C#中Npgsql.NpgsqlCommand.Cancel方法的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlCommand.Cancel方法的具体用法?C# NpgsqlCommand.Cancel怎么用?C# NpgsqlCommand.Cancel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Npgsql.NpgsqlCommand的用法示例。


在下文中一共展示了NpgsqlCommand.Cancel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Cancel

 public void Cancel()
 {
     using (var cmd = new NpgsqlCommand("SELECT pg_sleep(5)", Conn))
     {
         Task.Factory.StartNew(() =>
         {
             Thread.Sleep(300);
             cmd.Cancel();
         });
         Assert.That(() => cmd.ExecuteNonQuery(),
             Throws.TypeOf<NpgsqlException>()
             .With.Property("Code").EqualTo("57014")
         );
     }
 }
开发者ID:jbcooley,项目名称:Npgsql2,代码行数:15,代码来源:CommandTests.cs

示例2: CancelCrossCommand

 public void CancelCrossCommand()
 {
     using (var cmd1 = CreateSleepCommand(Conn, 2))
     using (var cmd2 = new NpgsqlCommand("SELECT 1", Conn)) {
         var cancelTask = Task.Factory.StartNew(() =>
         {
             Thread.Sleep(300);
             cmd2.Cancel();
         });
         Assert.That(() => cmd1.ExecuteNonQuery(), Throws.Nothing);
         cancelTask.Wait();
     }
 }
开发者ID:rwrz,项目名称:npgsql,代码行数:13,代码来源:CommandTests.cs

示例3: GetAllUsers

        //public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        public MembershipUserCollection GetAllUsers(string providerName, string applicationname, int pageIndex, int pageSize)
        {
            MembershipUserCollection users = new MembershipUserCollection();
            using (NpgsqlConnection conn = new NpgsqlConnection(GetConnectionString()))
            {
                string query = string.Format(
                    QRY_GET_ALL_USER_BY_APPLICATION,
                    applicationname);
                using (NpgsqlCommand cmd = new NpgsqlCommand(query, conn))
                {
                    NpgsqlDataReader reader = null;
                    try
                    {
                        conn.Open();
                        reader = cmd.ExecuteReader();
                        int counter = 0;
                        int startIndex = pageSize * pageIndex;
                        int endIndex = startIndex + pageSize - 1;
                        while (reader.Read())
                        {
                            if (counter >= startIndex)
                            {
                                MembershipUser u = GetUserFromReader(providerName, reader);
                                users.Add(u);
                            }

                            if (counter >= endIndex)
                                cmd.Cancel();
                            ++counter;
                        }
                    }
                    catch (NpgsqlException ex)
                    {
                        Logger.Instance.Write (TrackProtect.Logging.LogLevel.Error, ex, "GetAllUsers<NpgsqlException>");
                    }
                    finally
                    {
                        if (reader != null)
                            reader.Close();
                        conn.Close();
                    }
                }
            }
            return users;
        }
开发者ID:nageshverma2003,项目名称:TrackProtectSource,代码行数:46,代码来源:PostgresDatabase.cs

示例4: FindUsersByName

        public MembershipUserCollection FindUsersByName(string providerName, string usernameToMatch, string applicationname, int pageIndex, int pageSize, out int totalRecords)
        {
            MembershipUserCollection users = new MembershipUserCollection();
            using (NpgsqlConnection conn = new NpgsqlConnection(GetConnectionString()))
            {
                string query = string.Format(
                    QRY_SELECT_USER_COUNT_BY_NAME,
                    usernameToMatch,
                    applicationname);
                using (NpgsqlCommand cmd = new NpgsqlCommand(QRY_SELECT_USER_COUNT_BY_NAME, conn))
                {
                    NpgsqlDataReader reader = null;

                    try
                    {
                        conn.Open();
                        totalRecords = (int)cmd.ExecuteScalar();

                        if (totalRecords <= 0) { return users; }

                        query = string.Format(
                            QRY_GET_USER_BY_NAME_AND_APPLICATION_ORDERED,
                            usernameToMatch,
                            applicationname);
                        cmd.CommandText = query;

                        reader = cmd.ExecuteReader();

                        int counter = 0;
                        int startIndex = pageSize * pageIndex;
                        int endIndex = startIndex + pageSize - 1;

                        while (reader.Read())
                        {
                            if (counter >= startIndex)
                            {
                                MembershipUser u = GetUserFromReader(providerName, reader);
                                users.Add(u);
                            }

                            if (counter >= endIndex) { cmd.Cancel(); }

                            counter++;
                        }
                    }
                    catch (NpgsqlException e)
                    {
                        if (WriteExceptionsToEventLog)
                        {
                            WriteToEventLog(e, "FindUsersByName");

                            throw new ProviderException(EXCEPTION_MESSAGE);
                        }
                        else
                        {
                            throw e;
                        }
                    }
                    finally
                    {
                        if (reader != null) { reader.Close(); }

                        conn.Close();
                    }
                }
            }

            return users;
        }
开发者ID:nageshverma2003,项目名称:TrackProtectSource,代码行数:69,代码来源:PostgresDatabase.cs

示例5: timer_Tick


//.........这里部分代码省略.........
                    {
                        string[] permanentCurrentData = new string[4];
                        for (int f = 0; f < permanentCurrentData.Length; f++)
                        {
                            permanentCurrentData[f] = "";
                        }

                        if (tempCurrentData != "")
                        {
                            permanentCurrentData = parseCurrentData(tempCurrentData);
                        }

                        if (permanentCurrentData[0].Length > 900)
                        {
                            rec.CustomStr9 = permanentCurrentData[0].Substring(0,850);
                            rec.CustomStr10 = permanentCurrentData[0].Substring(851, 850);
                        }
                        else
                        {
                            rec.CustomStr9 = permanentCurrentData[0];
                        }

                        rec.CustomStr4 = permanentCurrentData[1];
                        rec.CustomStr5 = permanentCurrentData[2];
                        rec.CustomStr8 = permanentCurrentData[3];

                        L.Log(LogType.FILE, Log.LogLevel.INFORM, "rec.CustomStr4 Is : " + rec.CustomStr4);
                        L.Log(LogType.FILE, Log.LogLevel.INFORM, "rec.CustomStr5 Is : " + rec.CustomStr5);

                    }
                    catch (Exception ex)
                    {
                        L.Log(LogType.FILE, Log.LogLevel.ERROR, "In timer_Tick()-->> An Error Occured While Parsing current_data " + ex.Message);
                    }

                    string tempPrevData = "";
                    tempPrevData = readReader[5].ToString();
                    //L.Log(LogType.FILE, Log.LogLevel.INFORM, " (tempPrevData) is : " + tempPrevData);
                    string permanentPrevData = "";
                    if (tempPrevData != "")
                    {
                        permanentPrevData = parsePrevData(tempPrevData);
                    }

                    rec.CustomStr2 = permanentPrevData;

                    long recordID = Convert.ToInt64(readReader[8].ToString());

                    L.Log(LogType.FILE, Log.LogLevel.DEBUG, "Start sending Data");

                    if (usingRegistry)
                    {
                        CustomServiceBase s = base.GetInstanceService("Security Manager Sender");
                        s.SetData(rec);
                    }
                    else
                    {
                        CustomServiceBase s = base.GetInstanceService("Security Manager Remote Recorder");
                        s.SetData(Dal, virtualhost, rec);
                    }

                    L.Log(LogType.FILE, Log.LogLevel.DEBUG, "Finish Sending Data");

                    last_position = recordID;
                    last_recdate = rec.Datetime;
                    L.Log(LogType.FILE, Log.LogLevel.DEBUG, "Record Number is " + last_position.ToString());
                    i++;
                    if (i > max_record_send)
                    {
                        command.Cancel();
                        L.Log(LogType.FILE, Log.LogLevel.DEBUG, "max_record_send < " + i.ToString() + " and command canceled");
                        return;
                    }
                    lastDb = mcdb_name;
                    if (usingRegistry)
                        SetNetCadPostGre_Registry(last_position.ToString());
                    else
                    {
                        CustomServiceBase s = base.GetInstanceService("Security Manager Remote Recorder");
                        s.SetReg(Id, last_position.ToString(), "", lastDb, "", last_recdate);
                    }
                }
                L.Log(LogType.FILE, Log.LogLevel.DEBUG, "Finish getting the data");
            }
            catch (Exception er)
            {
                L.Log(LogType.FILE, Log.LogLevel.ERROR, er.ToString());
            }
            finally
            {
                timer.Enabled = true;
                L.Log(LogType.FILE, Log.LogLevel.INFORM, "Service Stopped");

                if (command != null)
                {
                    command.Dispose();
                }
                pgc.ClosePostGreConnection();
            }
        }
开发者ID:salimci,项目名称:Legacy-Remote-Recorder,代码行数:101,代码来源:NetCadPostGreRecorder.cs

示例6: DoWork

        public void DoWork()
        {
            using (NpgsqlConnection conn = new NpgsqlConnection(GlobalUtils.TopSecret.PostgresCS))
            using (NpgsqlCommand command = new NpgsqlCommand())
            {
                try
                {
                    conn.Open();
                    //conn.StatisticsEnabled = true;
                    command.Connection = conn;
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.Message);
                    return;
                }
                try
                {
                    using (NpgsqlTransaction sqlTran = conn.BeginTransaction())
                    {
                        command.Transaction = sqlTran;
                        NpgsqlDataReader reader;

                        List<string> commands = GetCommands(com);
                        foreach (string c in commands)
                        {
                            command.CommandText = c;
                            using (reader = command.ExecuteReader())
                            {
                                ShowResultSet(reader);
                                while (reader.NextResult())
                                    ShowResultSet(reader);
                            }
                        }
                        //var stats = conn.RetrieveStatistics();
                        //using (TextWriter tw = new StreamWriter(path + ".stats"))
                        //{
                        //    tw.WriteLine("Execution time: {0} sec, rows selected: {1}, rows affected: {2}",
                        //                    Math.Round((double)(long)stats["ExecutionTime"] / 1000, 2),
                        //                    stats["SelectRows"],
                        //                    stats["IduRows"]);
                        //}
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.Message);
                    if (command != null)
                        command.Cancel();
                }
            }
        }
开发者ID:ren85,项目名称:rextester_win,代码行数:52,代码来源:Program.cs

示例7: AddStudents_Click

        /*
        function name AddStudents_Click
        inputs: query
        outputs: add student studying lesson and cancel student studying lesson
        errors:
        */
        private void AddStudents_Click(object sender, EventArgs e)
        {
            string str = "Uid=postgres; Password=123; server=localhost; port=5432; Database=classmanagement;";
            NpgsqlConnection conn = new NpgsqlConnection(str);
            conn.Open();

            foreach (DataGridViewRow dr in dataGridView1.Rows)
            {
                int n = dr.Index;
                if (dr.Cells[0].Value != null)
                {

                    String insert = "";

                    String select1 = "SELECT studentname FROM attendance WHERE studentname='" + dataGridView1.Rows[n].Cells[1].Value + "'AND subjectname='" + comboBox1.Text + "'";
                    NpgsqlCommand select_command1 = new NpgsqlCommand(select1, conn);
                    NpgsqlDataReader read = select_command1.ExecuteReader();
                    if (read.Read())
                    {
                        MessageBox.Show("Error message", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        insert = "INSERT into attendance VALUES('" + dataGridView1.Rows[n].Cells[2].Value + "','" + dataGridView1.Rows[n].Cells[3].Value + "','" + comboBox1.Text + "')";
                        NpgsqlCommand command = new NpgsqlCommand(insert, conn);
                        command.ExecuteNonQuery();
                        command.Cancel();
                        String select = "SELECT name,start_time,start_minute,finish_time,finish_minute FROM subject WHERE name='" + comboBox1.Text + "'";
                        NpgsqlCommand select_command = new NpgsqlCommand(select, conn);
                        NpgsqlDataReader reader1 = select_command.ExecuteReader();
                        NpgsqlCommand baba = new NpgsqlCommand();
                        if (reader1.Read())
                        {
                            int num1 = Convert.ToInt32(reader1[1]);
                            int num2 = Convert.ToInt32(reader1[2]);
                            int num3 = Convert.ToInt32(reader1[3]);
                            int num4 = Convert.ToInt32(reader1[4]);
                            String ins = "INSERT into startfinish VALUES('" + comboBox1.Text.ToString() + "','" + dataGridView1.Rows[n].Cells[2].Value + "','" + dataGridView1.Rows[n].Cells[3].Value + "','" + num1 + "','" + num2 + "','" + num3 + "','" + num4 + "')";
                            baba = new NpgsqlCommand(ins, conn);

                        }
                        reader1.Close();
                        baba.ExecuteNonQuery();

                        insert = "INSERT into homework VALUES('" + dataGridView1.Rows[n].Cells[2].Value + "','" + dataGridView1.Rows[n].Cells[3].Value + "','" + comboBox1.Text.ToString() + "')";
                        NpgsqlCommand comm = new NpgsqlCommand(insert, conn);
                        comm.ExecuteNonQuery();

                        insert = "INSERT into grade VALUES('" + comboBox1.Text.ToString() + "','" + dataGridView1.Rows[n].Cells[2].Value + "','" + dataGridView1.Rows[n].Cells[3].Value + "')";
                        NpgsqlCommand comm1 = new NpgsqlCommand(insert, conn);
                        comm1.ExecuteNonQuery();

                        //MessageBox.Show("success.");
                    }
                    read.Close();
                }
                else
                {
                    String delete = "DELETE FROM attendance WHERE studentname='" + dataGridView1.Rows[n].Cells[2].Value + "' AND subjectname='"+comboBox1.Text+"'";
                    NpgsqlCommand comm = new NpgsqlCommand(delete, conn);
                    comm.ExecuteNonQuery();

                    delete = "DELETE FROM startfinish WHERE student_name='" + dataGridView1.Rows[n].Cells[2].Value + "' AND lesson_name='"+comboBox1.Text+"'";
                    NpgsqlCommand comm1 = new NpgsqlCommand(delete, conn);
                    comm1.ExecuteNonQuery();

                    delete = "DELETE FROM homework WHERE studentname='" + dataGridView1.Rows[n].Cells[2].Value + "' AND subjectname='" + comboBox1.Text + "'";
                    NpgsqlCommand comm2 = new NpgsqlCommand(delete, conn);
                    comm2.ExecuteNonQuery();

                    delete = "DELETE FROM grade WHERE student_name='" + dataGridView1.Rows[n].Cells[2].Value + "' AND lesson='" + comboBox1.Text + "'";
                    NpgsqlCommand comm3 = new NpgsqlCommand(delete, conn);
                    comm3.ExecuteNonQuery();
                }

            }
            conn.Close();
        }
开发者ID:gunchee,项目名称:class-management,代码行数:84,代码来源:Main.cs


注:本文中的Npgsql.NpgsqlCommand.Cancel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。