Skip to content

Instantly share code, notes, and snippets.

@RogerDunn RogerDunn/text.md
Last active Mar 11, 2019

Embed
What would you like to do?
Exponam Nuget Package Usage

Populating an Exponam .BIG file from a database

Exponam .BIG files are highly-compressed, encrypted, and immutable data files that can be viewed with the freely available Exponam Explorer.

The following is a simple example showing how an Exponam .BIG file can be generated from the result of a SQL query with just a few lines of C# code.

Please note that this example shows file generation both with and without the availability of an Exponam license.

You are free to generate files without a license, but the exported files will be subject to limits defined by Exponam.

A commercial or developer license for the Exponam software may be obtained by contacting Exponam.

    class ExponamDbBasedWriterExample
    {
        void PerformExports()
        {
            var connectionString = "..."; // The connection string to your database
            var tableToExport = "..."; // The name of the table (or view) that you'd like to export to a .BIG file

            ExportWithoutLicenseFile(connectionString, tableToExport, tableToExport + "-withoutLicense" + ".big");
            
            var licenseFile = "..."; // The full path to your the license file you received from Exponam
            var password = "..."; // The password to be used when encrypting the .BIG file
            ExportWithLicenseFile(licenseFile, connectionString, tableToExport, tableToExport + ".big", password);
        }

        static void ExportWithoutLicenseFile(string connectionString,
            string tableName,
            string exportFile)
        {
            ExportTableToBIG(connectionString, tableName, exportFile);
        }

        static void ExportWithLicenseFile(string licenseFile,
            string connectionString,
            string tableName,
            string exportFile,
            string password)
        {
            using (var licenseFileReader = new BinaryReader(new FileStream(licenseFile, FileMode.Open)))
            {
                ExportTableToBIG(connectionString, tableName, exportFile, licenseFileReader, password);
            }
        }

    static void ExportTableToBIG(string connectionString,
        string tableName,
        string outputFileName,
        BinaryReader licenseFileReader = null,
        string password = null)
        {
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("select * from " + tableName, conn);
            SqlDataReader reader = null;
            try
            {
                conn.Open();
                reader = cmd.ExecuteReader();

                BinaryWriter binaryWriter = new BinaryWriter(new FileStream(outputFileName, FileMode.Create));
                DbBasedWriter writer = new DbBasedWriter();
                writer.WriteFrom(reader, binaryWriter, licenseFileReader, password);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.