Exemplo n.º 1
0
        private BaseMetadataProvider GetMetadataProvider()
        {
            BaseMetadataProvider metaprov = null;

            switch (this.DatabasePlatform)
            {
            case QueryBuilderDatabasePlatform.MSSQLServer:
                metaprov            = new MSSQLMetadataProvider();
                metaprov.Connection = new SqlConnection(this.ConnectionString);
                break;

            case QueryBuilderDatabasePlatform.SQLServerCE:
                //metaprov = new MSSQLCEMetadataProvider();  //does not work
                //metaprov = new UniversalMetadataProvider();  //does not work
                //metaprov.Connection = new SqlCeConnection(this.ConnectionString);

                string oledbConnectionString = ConvertSQLCE35ConnectionStringToOLEDB(this.ConnectionString);
                metaprov            = new OLEDBMetadataProvider();
                metaprov.Connection = new OleDbConnection(oledbConnectionString);
                queryBuilder.DatabaseSchemaTreeOptions.DefaultExpandLevel = 0;
                break;

            case QueryBuilderDatabasePlatform.OLEDB:
                metaprov            = new OLEDBMetadataProvider();
                metaprov.Connection = new OleDbConnection(this.ConnectionString);
                break;

            case QueryBuilderDatabasePlatform.ODBC:
                metaprov            = new ODBCMetadataProvider();
                metaprov.Connection = new OdbcConnection(this.ConnectionString);
                break;

            case QueryBuilderDatabasePlatform.MSAccess:
                metaprov            = new OLEDBMetadataProvider();
                metaprov.Connection = new OleDbConnection(this.ConnectionString);
                queryBuilder.DatabaseSchemaTreeOptions.DefaultExpandLevel = 0;
                break;

            case QueryBuilderDatabasePlatform.Oracle:
                metaprov            = new OracleMetadataProvider();
                metaprov.Connection = new System.Data.OracleClient.OracleConnection(this.ConnectionString);
                queryBuilder.DatabaseSchemaTreeOptions.DefaultExpandLevel = 0;
                break;

            default:
                metaprov            = new UniversalMetadataProvider();
                metaprov.Connection = new OdbcConnection(this.ConnectionString);
                break;
            }

            return(metaprov);
        }
Exemplo n.º 2
0
        public void QueryBuilderControl1_Init(object sender, EventArgs e)
        {
            // Get instance of QueryBuilder
            QueryBuilder queryBuilder = QueryBuilderControl1.QueryBuilder;

            queryBuilder.OfflineMode = false;
            // Turn this property on to suppress parsing error messages when user types non-SELECT statements in the text editor.
            queryBuilder.BehaviorOptions.AllowSleepMode = true;
            queryBuilder.SyntaxProvider = new MSAccessSyntaxProvider();

            // you may load metadata from the database connection using live database connection and metadata provider
            var connection = CreateConnection();

            if (string.IsNullOrEmpty(connection.ConnectionString))
            {
                string message = "Can't find in [web.config] key <configuration>/<connectionStrings><add key=\"YourDB\" connectionString=\"...\">!";
                Logger.Error(message);
                queryBuilder.OfflineMode = true;
                return;
            }

            try
            {
                var metadataProvider = new OLEDBMetadataProvider();
                metadataProvider.Connection   = connection;
                queryBuilder.MetadataProvider = metadataProvider;
            }
            catch (Exception ex)
            {
                string message = "Can't setup metadata provider!";
                Logger.Error(message, ex);
                return;
            }


            // Initialization of the Metadata Structure object that's
            // responsible for representation of metadata in a tree-like form
            try
            {
                // Clears and loads the first level of the metadata structure tree
                queryBuilder.MetadataStructure.Refresh();
                StatusBar1.Message.Information("Metadata loaded");
            }
            catch (Exception ex)
            {
                string message =
                    "Error loading metadata from the database." +
                    "Check the 'configuration\\connectionStrings' key in the [web.config] file.";
                Logger.Error(message, ex);
                StatusBar1.Message.Error(message + " Check log.txt for details.");
            }
        }
        private void btnTest_Click(object sender, RoutedEventArgs e)
        {
            var metadataProvider = new OLEDBMetadataProvider {
                Connection = new OleDbConnection(ConnectionString)
            };
            Type syntaxProviderType = null;

            try
            {
                syntaxProviderType = Helpers.AutodetectSyntaxProvider(metadataProvider);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Error");
            }

            DoSyntaxDetected(syntaxProviderType);
        }
        private static void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // Create temporary QueryBuilder instance
            using (SQLContext sqlContext = new SQLContext())
            {
                // Create temporary MetadataProvider
                using (OLEDBMetadataProvider oledbMetadataProvider = new OLEDBMetadataProvider())
                {
                    // Create connection to database
                    oledbMetadataProvider.Connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=demo.mdb");
                    // Set up the QueryBuilder
                    sqlContext.MetadataProvider = oledbMetadataProvider;
                    sqlContext.SyntaxProvider   = new MSAccessSyntaxProvider();
                    // Load metadata, force fields loading for all metadata objects
                    sqlContext.MetadataContainer.LoadAll(true);

                    // Put copy of filled metadata container to worker result
                    e.Result = sqlContext.MetadataContainer.Clone(sqlContext);
                }
            }
        }