public static bool Go(string dbType, string connectionString, string pathToScriptFile)
        {
            StreamReader _reader = (StreamReader)null;
            Stream       stream  = (Stream)null;

            if (!File.Exists(pathToScriptFile))
            {
                return(false);
            }
            try
            {
                stream  = (Stream)File.OpenRead(pathToScriptFile);
                _reader = new StreamReader(stream, Encoding.UTF8);
                if (dbType == "0")
                {
                    using (OleDbConnection oleDbConnection = new OleDbConnection(connectionString))
                    {
                        using (OleDbCommand oleDbCommand = new OleDbCommand())
                        {
                            oleDbConnection.Open();
                            oleDbCommand.Connection  = oleDbConnection;
                            oleDbCommand.CommandType = CommandType.Text;
                            string str;
                            while ((str = ExecuteSqlBlock.ReadNextStatementFromStream(_reader)) != null)
                            {
                                oleDbCommand.CommandText = str;
                                oleDbCommand.ExecuteNonQuery();
                            }
                        }
                    }
                }
                else
                {
                    using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                    {
                        using (SqlCommand sqlCommand = new SqlCommand())
                        {
                            sqlConnection.Open();
                            sqlCommand.Connection     = sqlConnection;
                            sqlCommand.CommandTimeout = 180;
                            sqlCommand.CommandType    = CommandType.Text;
                            string str;
                            while ((str = ExecuteSqlBlock.ReadNextStatementFromStream(_reader)) != null)
                            {
                                sqlCommand.CommandText = str;
                                sqlCommand.ExecuteNonQuery();
                            }
                        }
                    }
                }
                return(true);
            }
            catch
            {
                return(false);
            }
            finally
            {
                _reader.Close();
                _reader.Dispose();
                stream.Close();
                stream.Dispose();
            }
        }
Example #2
0
        public static bool Go(string dbType, string connectionString, string pathToScriptFile)
        {
            StreamReader streamReader = null;
            Stream       stream       = null;

            if (!File.Exists(pathToScriptFile))
            {
                return(false);
            }
            bool result;

            try
            {
                stream       = File.OpenRead(pathToScriptFile);
                streamReader = new StreamReader(stream, Encoding.UTF8);
                if (dbType == "0")
                {
                    using (OleDbConnection oleDbConnection = new OleDbConnection(connectionString))
                    {
                        using (OleDbCommand oleDbCommand = new OleDbCommand())
                        {
                            oleDbConnection.Open();
                            oleDbCommand.Connection  = oleDbConnection;
                            oleDbCommand.CommandType = CommandType.Text;
                            string commandText;
                            while ((commandText = ExecuteSqlBlock.ReadNextStatementFromStream(streamReader)) != null)
                            {
                                oleDbCommand.CommandText = commandText;
                                oleDbCommand.ExecuteNonQuery();
                            }
                        }
                        goto IL_F9;
                    }
                }
                using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                {
                    using (SqlCommand sqlCommand = new SqlCommand())
                    {
                        sqlConnection.Open();
                        sqlCommand.Connection     = sqlConnection;
                        sqlCommand.CommandTimeout = 180;
                        sqlCommand.CommandType    = CommandType.Text;
                        string commandText;
                        while ((commandText = ExecuteSqlBlock.ReadNextStatementFromStream(streamReader)) != null)
                        {
                            sqlCommand.CommandText = commandText;
                            sqlCommand.ExecuteNonQuery();
                        }
                    }
                }
IL_F9:
                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                streamReader.Close();
                streamReader.Dispose();
                stream.Close();
                stream.Dispose();
            }
            return(result);
        }