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


C# SqlCommand.ExecuteScalarRetryOnDeadlock方法代码示例

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


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

示例1: GetFileName

 public static string GetFileName(Guid id)
 {
     using (SqlConnection connection = new SqlConnection(Config.ConnectionString))
     {
         connection.Open();
         using (SqlCommand cmd = new SqlCommand("SELECT fileName FROM Documents WHERE id = @id", connection))
         {
             cmd.CommandTimeout = Config.CommandTimeout;
             cmd.AssignParams("id", id);
             return (string)cmd.ExecuteScalarRetryOnDeadlock();
         }
     }
 }
开发者ID:project-first,项目名称:documentviewerservice,代码行数:13,代码来源:Utils.cs

示例2: SentimentWordOccurrenceToDb

        public static long SentimentWordOccurrenceToDb(SqlConnection connection, string date, int locationStart, int locationEnd, int sentenceNum, int blockNum, long document_id, string entityUri)
        {
            using (SqlCommand cmd = new SqlCommand(null, connection))
            {
                cmd.CommandTimeout = 300;
                cmd.CommandText = ClSentimentWordOccurrence;
                //  Console.WriteLine("\n -------------------"+entityUri);
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@date", date);
                cmd.Parameters.AddWithValue("@locationStart", locationStart);
                cmd.Parameters.AddWithValue("@locationEnd", locationEnd);
                cmd.Parameters.AddWithValue("@sentenceNum", sentenceNum);
                cmd.Parameters.AddWithValue("@blockNum", blockNum);
                cmd.Parameters.AddWithValue("@document_id", document_id);
                cmd.Parameters.AddWithValue("@entityUri", entityUri);

                try
                {
                    Decimal tmp = (Decimal)cmd.ExecuteScalarRetryOnDeadlock();
                    long id = Decimal.ToInt32(tmp);  //Execute the command, get id of the inserted document
                    return id;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\nError inserting sentiment word occurrence " + entityUri + "\n" + ex);
                    return 0;
                }
            }
        }
开发者ID:project-first,项目名称:monitorpipeline,代码行数:29,代码来源:ToDb.cs

示例3: OccurrenceToDb

        public static long OccurrenceToDb(SqlConnection connection, string date, int locationStart, int locationEnd, int sentenceNum, int blockNum, long document_id, string entityUri)
        {
            using (SqlCommand cmd = new SqlCommand(null, connection))
            {
                cmd.CommandTimeout = 300;
                cmd.CommandText = ClOccurrence;
                //  Console.WriteLine("\n -------------------"+entityUri);
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@date", date);
                cmd.Parameters.AddWithValue("@locationStart", locationStart);
                cmd.Parameters.AddWithValue("@locationEnd", locationEnd);
                cmd.Parameters.AddWithValue("@sentenceNum", sentenceNum);
                cmd.Parameters.AddWithValue("@blockNum", blockNum);
                cmd.Parameters.AddWithValue("@document_id", document_id);
                cmd.Parameters.AddWithValue("@entityUri", entityUri);

                try
                {
                    Decimal tmp = (Decimal)cmd.ExecuteScalarRetryOnDeadlock();
                    long id = Decimal.ToInt32(tmp);  //Execute the command, get id of the inserted document
                    return id;
                }
                catch (Exception ex)
                {
                    string errorMessage = String.Format("\nError inserting occurrence: \n\t\t DocumentId:{0} \n\t\tEntityUri:{1}", document_id, entityUri);
                    throw new Exception(ex + errorMessage);
                }
            }
        }
开发者ID:project-first,项目名称:monitorpipeline,代码行数:29,代码来源:ToDb.cs

示例4: DocumentToDb

        /// <summary>
        /// Inserts the data about the document document table in the semantics database.
        /// </summary>
        public static long DocumentToDb(SqlConnection connection, string title, string date, string pubDate, string timeGet, string responseUrl, string urlKey, string domainName, bool isFinancial, double pumpDumpIndex, Guid documentGuid)
        {
            using (SqlCommand cmd = new SqlCommand(null, connection))
            {
                cmd.CommandTimeout = 300;
                cmd.CommandText = ClDocument;

                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@title", Shorten(title, 1000));
                cmd.Parameters.AddWithValue("@date", date);
                cmd.Parameters.AddWithValue("@pubDate", Shorten(pubDate, 100));
                cmd.Parameters.AddWithValue("@timeGet", timeGet);
                cmd.Parameters.AddWithValue("@responseUrl", Shorten(responseUrl, 1000));
                cmd.Parameters.AddWithValue("@urlKey", Shorten(urlKey, 1000));
                cmd.Parameters.AddWithValue("@domainName", Shorten(domainName, 255));

                cmd.Parameters.AddWithValue("@isFinancial", isFinancial);
                cmd.Parameters.AddWithValue("@pumpDumpIndex", pumpDumpIndex);
                cmd.Parameters.AddWithValue("@documentGuid", documentGuid);

                try
                {
                    long id = Decimal.ToInt32((Decimal)cmd.ExecuteScalarRetryOnDeadlock());  //Execute the command, get id of the inserted document
                    return id;
                }
                catch (SqlException ex)
                {
                    string errorMessage = String.Format("\nError inserting document: \r\nThe document: \n\t\tTitle:{0} \n\t\tDate:{1} \n\t\tUrlKey:{2}", title, date, urlKey);
                    throw new Exception(ex + errorMessage);
                }
            }
        }
开发者ID:project-first,项目名称:monitorpipeline,代码行数:35,代码来源:ToDb.cs


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