static public IDbConnection CreateConnection(string ProviderName, string ConnectionString) { if (ProviderName == null) { throw new System.ArgumentNullException("ProviderName"); } if (ConnectionString == null) { throw new System.ArgumentNullException("ConnectionString"); } Provider provider = providers [ProviderName]; if (provider == null) { throw new ArgumentException("ProviderName", "The specified provider does not exist"); } IDbConnection conn = provider.CreateConnection(); conn.ConnectionString = ConnectionString; return(conn); }
public bool OpenDataSource (Provider theProvider, string theConnectionString, string connectionName) { provider = theProvider; connectionString = theConnectionString; string msg; msg = "Attempt to open connection..."; AppendText (msg); conn = null; try { switch (provider.Name) { case "System.Data.SqlClient": conn = new SqlConnection (); break; case "System.Data.Odbc": conn = new OdbcConnection (); break; case "System.Data.OleDb": conn = new OleDbConnection (); break; default: conn = provider.CreateConnection (); break; } } catch (Exception e) { msg = "Error: Unable to create Connection object. \n" + "Check to make sure the provider is setup correctly in your config file. \n" + e.Message; Error (msg); return false; } ConnectionString conString = new ConnectionString (connectionString); conn.ConnectionString = connectionString; try { conn.Open (); if( conn.State == ConnectionState.Open) AppendText ("Open was successfull."); else { AppendText ("Error: Open failed."); return false; } } catch (Exception e) { msg = "Error: Could not open data source: " + e.Message; Error (msg); conn = null; return false; } // database connected - do other things //SetStatusBarText ("Connected."); lastConnection++; string dataSourceName = ""; if (connectionName.Equals("")) dataSourceName = lastConnection.ToString () + ":" + provider.Name; else dataSourceName = lastConnection.ToString () + ":" + connectionName; dataSource = new DataSourceConnection (dataSourceName, connectionName, provider, conString, conn); dataSources.Add (dataSource); combo.AppendText (dataSourceName); ComboHelper.SetActiveText (combo, dataSourceName); TreeIter iterDataSource = tree.Store.AppendValues (tree.RootIter, dataSourceName, ""); tree.Store.SetValue(iterDataSource, 1, ""); //string sz = tree.Store.GetValue(iterDataSource, 1).ToString(); //AppendText("sz: " + sz); // TODO: only load meta data when the user expands a tree node // or Refreshes SetStatusBarText ("Getting Meta Data..."); while (Application.EventsPending ()) Application.RunIteration (); PopulateTables (iterDataSource, provider, conn, true); //PopulateViews (iterDataSource, provider, conn); //PopulateProcedures (iterDataSource, provider, conn); SetStatusBarText ("Connected."); SetFocusToEditor (); return true; }