// Gets a database connection to the Oracle database configured earlier in the setup. private IDbConnection GetOracleConnection() { OracleSetup oracleSetup = m_state["oracleSetup"] as OracleSetup; string connectionString = (oracleSetup == null) ? null : oracleSetup.ConnectionString; string dataProviderString = (oracleSetup == null) ? OracleSetup.DefaultDataProviderString : oracleSetup.DataProviderString; return(GetConnection(connectionString, dataProviderString)); }
private IDbConnection OpenNewConnection() { IDbConnection connection = null; try { string databaseType = m_state["newDatabaseType"].ToString(); string connectionString = string.Empty; string dataProviderString = string.Empty; if (databaseType == "SQLServer") { SqlServerSetup sqlServerSetup = m_state["sqlServerSetup"] as SqlServerSetup; connectionString = sqlServerSetup.ConnectionString; dataProviderString = sqlServerSetup.DataProviderString; if (string.IsNullOrWhiteSpace(dataProviderString)) { dataProviderString = "AssemblyName={System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}; ConnectionType=System.Data.SqlClient.SqlConnection; AdapterType=System.Data.SqlClient.SqlDataAdapter"; } } else if (databaseType == "MySQL") { MySqlSetup mySqlSetup = m_state["mySqlSetup"] as MySqlSetup; connectionString = mySqlSetup.ConnectionString; dataProviderString = mySqlSetup.DataProviderString; if (string.IsNullOrWhiteSpace(dataProviderString)) { dataProviderString = "AssemblyName={MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d}; ConnectionType=MySql.Data.MySqlClient.MySqlConnection; AdapterType=MySql.Data.MySqlClient.MySqlDataAdapter"; } } else if (databaseType == "Oracle") { OracleSetup oracleSetup = m_state["oracleSetup"] as OracleSetup; connectionString = oracleSetup.ConnectionString; dataProviderString = oracleSetup.DataProviderString; if (string.IsNullOrWhiteSpace(dataProviderString)) { dataProviderString = OracleSetup.DefaultDataProviderString; } } else if (databaseType == "PostgreSQL") { PostgresSetup postgresSetup = m_state["postgresSetup"] as PostgresSetup; connectionString = postgresSetup.ConnectionString; dataProviderString = PostgresSetup.DataProviderString; } else { string destination = m_state["sqliteDatabaseFilePath"].ToString(); connectionString = "Data Source=" + destination + "; Version=3"; dataProviderString = "AssemblyName={System.Data.SQLite, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139}; ConnectionType=System.Data.SQLite.SQLiteConnection; AdapterType=System.Data.SQLite.SQLiteDataAdapter"; } if (!string.IsNullOrEmpty(connectionString) && !string.IsNullOrEmpty(dataProviderString)) { Dictionary <string, string> dataProviderSettings = dataProviderString.ParseKeyValuePairs(); string assemblyName = dataProviderSettings["AssemblyName"]; string connectionTypeName = dataProviderSettings["ConnectionType"]; Assembly assembly = Assembly.Load(new AssemblyName(assemblyName)); Type connectionType = assembly.GetType(connectionTypeName); connection = (IDbConnection)Activator.CreateInstance(connectionType); connection.ConnectionString = connectionString; connection.Open(); } } catch (Exception ex) { MessageBox.Show("Failed to open new database connection: " + ex.Message, "Configuration Error", MessageBoxButton.OK, MessageBoxImage.Error); if (connection != null) { connection.Dispose(); } connection = null; } return(connection); }
/// <summary> /// Creates a new instance of the <see cref="OracleDatabaseSetupScreen"/> class. /// </summary> public OracleDatabaseSetupScreen() { m_oracleSetup = new OracleSetup(); InitializeComponent(); this.Loaded += new RoutedEventHandler(OracleDatabaseSetupScreen_Loaded); }
/// <summary> /// Creates a new instance of the <see cref="OracleDatabaseSetupScreen"/> class. /// </summary> public OracleDatabaseSetupScreen() { m_oracleSetup = new OracleSetup(); InitializeComponent(); this.Loaded += new RoutedEventHandler(OracleDatabaseSetupScreen_Loaded); }