private static void UsingConnection(EFIngresConnection connection, Action <EFIngresConnection> act) { // remember the connection string so that we can reset it if credentials are wiped var holdConnectionString = connection.ConnectionString; var openingConnection = connection.State == ConnectionState.Closed; if (openingConnection) { connection.Open(); } try { act(connection); } finally { if (openingConnection && connection.State == ConnectionState.Open) { // if we opened the connection, we should close it connection.Close(); } if (connection.ConnectionString != holdConnectionString) { connection.ConnectionString = holdConnectionString; } } }
private static EFIngresCommand CreateCommand(EFIngresConnection connection, string commandText, int?commandTimeout) { Debug.Assert(connection != null); var command = new EFIngresCommand(commandText, connection); if (commandTimeout.HasValue) { command.CommandTimeout = commandTimeout.Value; } return(command); }
private static string GetDatabaseName(EFIngresConnection ingresConnection) { string databaseName = ingresConnection.Database; if (string.IsNullOrEmpty(databaseName)) { throw new InvalidOperationException("Connection String did not specify an Initial Catalog"); } return(databaseName); }
private static void UsingMasterConnection(EFIngresConnection connection, Action <EFIngresConnection> act) { var connectionBuilder = new IngresConnectionStringBuilder(connection.ConnectionString) { Database = "iidbdb" }; using (var masterConnection = new EFIngresConnection(connectionBuilder.ConnectionString)) { UsingConnection(masterConnection, act); } }
protected T Execute <T>(Func <T> execute) { ModifiedCommandText = null; ModifiedParameters = null; T result; var eventArgs = new EFIngresCommandEventArgs { Command = this, Success = true }; using (new CultureReestablisher()) { EFIngresConnection.OnCommandStarted(eventArgs); try { if (Direct) { result = execute(); eventArgs.Result = result; } else { using (var parser = new CommandParser(this)) { ModifiedCommandText = CommandText; ModifiedParameters = Parameters.Cast <IDbDataParameter>().ToList(); EFIngresConnection.OnCommandModified(eventArgs); EFIngresConnection.CatalogHelpers.CreateCatalogs(parser.CatalogTables); result = execute(); eventArgs.Result = result; } } } catch (Exception ex) { ex = new EFIngresCommandException(this, ex.Message, ex); eventArgs.Success = false; eventArgs.Error = ex; throw ex; } finally { EFIngresConnection.OnCommandExecuted(eventArgs); } } return(result); }
/// <summary> /// Get the EFIngresStoreVersion from the connection. /// </summary> /// <param name="connection">current sql connection</param> /// <returns>EFIngresStoreVersion corresponding to the current connection</returns> public static EFIngresStoreVersion GetStoreVersion(EFIngresConnection connection) { // IngresConnection.ServerVersion should be something like: "09.02.0001 II 9.2.1 (a64.lnx/103)NPTL" var match = Regex.Match(connection.ServerVersion, @"II (\w+)\.(\w+)\.(\w+)"); if (match.Success) { var serverVersion = new EFIngresStoreVersion(int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value), int.Parse(match.Groups[3].Value)); var version = EFIngresStoreVersion.Versions .Where(x => x.CompareTo(serverVersion) <= 0) .OrderByDescending(x => x) .FirstOrDefault(); if (version != null) { return(version); } } throw new ArgumentException("The version of Ingres [ " + connection.ServerVersion + " ] is not supported via Ingres Entity Framework provider."); }
public EFIngresCommand(string commandText, EFIngresConnection connection) { _wrappedCommand = new IngresCommand(); CommandText = commandText; DbConnection = connection; }
public EFIngresCommand(EFIngresConnection connection) : this(null, connection) { }
private static void GetDatabaseFileNames(EFIngresConnection connection, out string dataFileName, out string logFileName) { throw new NotSupportedException(); }
internal EFIngresConnectionEventArgs(EFIngresConnection connection) { Connection = connection; OriginalState = connection.State; CurrentState = connection.State; }