本文整理汇总了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();
}
}
}
示例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;
}
}
}
示例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);
}
}
}
示例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);
}
}
}