Beispiel #1
0
        /// <summary>
        /// Runs a SQL command from file
        /// </summary>
        /// <param name="assembly">An assembly containing the manifest resource.</param>
        /// <param name="resourceName">The name of the manifest resource.</param>
        /// <param name="connectionStringName">The name of the connection string</param>
        public static void RunExecuteNonQueryFromManifestResource(System.Reflection.Assembly assembly, string resourceName, string connectionStringName)
        {
            // NULL-check the assembly parameter
            if (assembly == null)
            {
                throw new System.ArgumentNullException(nameof(assembly));
            }

            // NULL-check the resourceName parameter
            if (string.IsNullOrWhiteSpace(resourceName))
            {
                throw new System.ArgumentNullException(nameof(resourceName));
            }

            // NULL-check the connectionStringName parameter
            if (string.IsNullOrWhiteSpace(connectionStringName))
            {
                throw new System.ArgumentNullException(nameof(connectionStringName));
            }

            // Get the contents of the manifest resource, pass each section (within a "GO" statement) to a sql command.
            var fullScript = assembly.GetManifestResourceString(resourceName);

            foreach (var scriptSegment in fullScript.Split(new[] { "\nGO" }, System.StringSplitOptions.RemoveEmptyEntries))
            {
                RunExecuteNonQuery(scriptSegment, connectionStringName);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Runs a SQL command from file
        /// </summary>
        /// <param name="assembly">An assembly containing the manifest resource.</param>
        /// <param name="resourceName">The name of the manifest resource.</param>
        /// <param name="connectionStringName">The name of the connection string</param>
        /// <returns>The result of the database query</returns>
        public static object RunExecuteScalarFromManifestResource(System.Reflection.Assembly assembly, string resourceName, string connectionStringName)
        {
            // NULL-check the assembly parameter
            if (assembly == null)
            {
                throw new System.ArgumentNullException(nameof(assembly));
            }

            // NULL-check the resourceName parameter
            if (string.IsNullOrWhiteSpace(resourceName))
            {
                throw new System.ArgumentNullException(nameof(resourceName));
            }

            // NULL-check the connectionStringName parameter
            if (string.IsNullOrWhiteSpace(connectionStringName))
            {
                throw new System.ArgumentNullException(nameof(connectionStringName));
            }

            // Get the contents of the manifest resource and pass it to a sql command.
            return(RunExecuteScalar(assembly.GetManifestResourceString(resourceName), connectionStringName: connectionStringName));
        }