Last active
August 29, 2015 14:01
-
-
Save BrianRosamilia/242d5cc46dd6b0a9a69b to your computer and use it in GitHub Desktop.
C#/MariaDB code that lets you easily pick an isolation level and read only flag to maximize throughput of queries that can be read only with dirty reads allowed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MySql.Data.MySqlClient; | |
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using System.Linq; | |
using System.Web; | |
using Dapper; | |
namespace Gist | |
{ | |
public class Utils | |
{ | |
public static readonly string ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; | |
private const string ReadOnlySession = "set session transaction isolation level read uncommitted, READ ONLY"; | |
internal static MySqlConnection CreateConnection() | |
{ | |
var connection = new MySqlConnection(ConnectionString); | |
connection.Open(); | |
return connection; | |
} | |
internal static MySqlConnection CreateConnectionReadUncommitted() | |
{ | |
var connection = new MySqlConnection(ConnectionString); | |
connection.Open(); | |
connection.Execute(ReadOnlySession); | |
return connection; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment