chucknorris / roundhouse

RoundhousE is a Database Migration Utility for .NET using sql files and versioning based on source control
http://projectroundhouse.org
920 stars 247 forks source link

Connection to oracle: StructureMap exception 207 #62

Open itemrdo opened 12 years ago

itemrdo commented 12 years ago

I'm trying to setup roundhouse for oracle:

rh.exe --connectionstring="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyOracleHost)(PORT=1521))(CONNECT_DATA=(SID=MyOracleSID)));User Id=MyUserId;Password=MyPassword;Persist Security Info=false" -vf=revision.xml -vx=//commit/@revision -env=UNITTEST -ni --runallanytimescripts --dt=roundhouse.databases.oracle

I have installed the oracle client, but I get the following exception:

StructureMap Exception Code: 207 Internal exception while creating Instance 'c9958e7c-cac9-4d25-a47d-d7eae39b882b' of PluginType roundhouse.databases.Database, rh, Version=0.7.0.281, Culture=neutral, PublicKeyToken=null. Check the inner exception for more details.

No innerexception is shown, no logfile is created and no entries are added to the windows event log.

Any ideas?

ferventcoder commented 12 years ago

Do you run into this issue if you run 0.8.5?

itemrdo commented 12 years ago

Yes, 0.8.5 gave me the same exception.

I debugged the application to found out it was because I hadn't supplied the assembly name for the database type (a clearer error message would have been more convenien though): --dt=roundhouse.databases.oracle should have been: --dt="roundhouse.databases.oracle.OracleDatabase, roundhouse.databases.oracle"

..which let me continue to the next set of exceptions. I had to make a few code changes to get RoundhousE working on Oracle:

  1. "Had an error building session factory from merged, attempting unmerged. The error: FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. ---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. ---> System.TypeLoadException: Could not load type 'roundhouse.databases.oracle.orm.VersionMapping' from assembly 'roundhouse, Version=0.0.0.0, Culture=neutral, PublicKeyToken=91b86fd44f1f23bc'."

    ==> I hacked my way out of this one by adding the roundhouse.databases.oracle.orm classes to the roundhouse assembly

    1. "RoundhousE encountered an error. System.ArgumentException: The OracleParameter is already contained by another OracleParameterCollection. at System.Data.OracleClient.OracleParameterCollection.Validate(Int32 index, Object value) at System.Data.OracleClient.OracleParameterCollection.Add(Object value) at roundhouse.databases.AdoNetDatabase.setup_database_command(String sql_to_run, ConnectionType connection_type, IEnumerable1 parameters) at roundhouse.databases.AdoNetDatabase.run_command_with(String sql_to_run, ConnectionType connection_type, IList1 parameters) at roundhouse.databases.AdoNetDatabase.run_sql(String sql_to_run, ConnectionType connection_type, IList`1 parameters) at roundhouse.databases.oracle.OracleDatabase.insert_version_and_get_version_id(String repository_path, String repository_version) at roundhouse.migrators.DefaultDatabaseMigrator.version_the_database(String repository_path, String repository_version) at roundhouse.runners.RoundhouseMigrationRunner.run()"

==> fixed by changing roundhouse.databases.AdoNetDatabase:180 command.Parameters.Add(parameter.underlying_type); to command.Parameters.Add(((ICloneable)parameter.underlying_type).Clone());

  1. "RoundhousE encountered an error. System.Data.OracleClient.OracleException: ORA-01008: not all variables bound

    at System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle, Int32 rc) at System.Data.OracleClient.OracleCommand.Execute(OciStatementHandle statementHandle, CommandBehavior behavior, Boolean needRowid, OciRowidDescriptor& rowidDescriptor, ArrayList& resultParameterOrdinals) at System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, OciRowidDescriptor& rowidDescriptor) at System.Data.OracleClient.OracleCommand.ExecuteNonQuery() at roundhouse.databases.AdoNetDatabase.run_command_with(String sql_to_run, ConnectionType connection_type, IList1 parameters) at roundhouse.databases.AdoNetDatabase.run_sql(String sql_to_run, ConnectionType connection_type, IList1 parameters) at roundhouse.databases.oracle.OracleDatabase.insert_version_and_get_version_id(String repository_path, String repository_version) at roundhouse.migrators.DefaultDatabaseMigrator.version_the_database(String repository_path, String repository_version) at roundhouse.runners.RoundhouseMigrationRunner.run()"

==> fixed by adding if (parameter.value == null) parameter.underlying_type.Value = DBNull.Value; above command.Parameters.Add(((ICloneable)parameter.underlying_type).Clone()); in roundhouse.databases.AdoNetDatabase

  1. "RoundhousE encountered an error. System.NullReferenceException: Object reference not set to an instance of an object. at roundhouse.databases.oracle.OracleDatabase.insert_version_and_get_version_id(String repository_path, String repository_version) in D:\Projects\temp\RoundhousE\product\roundhouse.databases.oracle\OracleDatabase.cs:line 135 at roundhouse.migrators.DefaultDatabaseMigrator.version_the_database(String repository_path, String repository_version) in D:\Projects\temp\RoundhousE\product\roundhouse\migrators\DefaultDatabaseMigrator.cs:line 159 at roundhouse.runners.RoundhouseMigrationRunner.run() in D:\Projects\temp\RoundhousE\product\roundhouse\runners\RoundhouseMigrationRunner.cs:line 128"

==> fixed by changing get_version_id_script() in roundhouse.databases.oracle.OracleDatabase:

    public string get_version_id_script(string repositoryPath)
    {
        return string.Format(
            @"
                SELECT id
                FROM (SELECT * FROM {0}_{1}
                        {0}
                        ORDER BY entry_date DESC)
                WHERE ROWNUM < 2
            ",
             roundhouse_schema_name, version_table_name, string.IsNullOrEmpty(repositoryPath) ? "" : "WHERE repository_path = :repository_path");
    }

and by changing the calling code in insert_version_and_get_version_id():

        var select_parameters = new List<IParameter<IDbDataParameter>>();
        if (!string.IsNullOrEmpty(repository_path)) select_parameters.Add(create_parameter("repository_path", DbType.AnsiString, repository_path, 255));
        return Convert.ToInt64((decimal)run_sql_scalar(get_version_id_script(repository_path), ConnectionType.Default, select_parameters)); 
  1. "System.Data.OracleClient.OracleException: ORA-01017: invalid username/password; logon denied at System.Data.OracleClient.OracleException.Check(OciErrorHandle errorHandle,Int32 rc) at System.Data.OracleClient.OracleInternalConnection.OpenOnLocalTransaction(String userName, String password, String serverName, Boolean integratedSecurity,Boolean unicode, Boolean omitOracleConnectionName) at System.Data.OracleClient.OracleInternalConnection..ctor(OracleConnectionString connectionOptions) at System.Data.OracleClient.OracleConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.OracleClient.OracleConnection.Open() at roundhouse.connections.AdoNetConnection.open() in D:\Projects\temp\RoundhousE\product\roundhouse\connections\AdoNetConnection.cs:line 18 at roundhouse.databases.AdoNetDatabase.open_admin_connection() in D:\Projects\temp\RoundhousE\product\roundhouse\databases\AdoNetDatabase.cs:line 39 at roundhouse.migrators.DefaultDatabaseMigrator.open_admin_connection() in D:\Projects\temp\RoundhousE\product\roundhouse\migrators\DefaultDatabaseMigrator.cs:line 48 at roundhouse.runners.RoundhouseMigrationRunner.run() in D:\Projects\temp\RoundhousE\product\roundhouse\runners\RoundhouseMigrationRunner.cs:line 134 ORA-01017: invalid username/password; logon denied"

==> I didn't look into this one, and just copied my connectionstring in --connectionstringadministration

ferventcoder commented 12 years ago

I admit the oracle side of the house needs more love.