예제 #1
0
        public long BulkCopy(string pNomeTabela, string pSqlCommand, BulkConfig pBulkConfig)
        {
            _rowsCopied = 0;
            try
            {
                using (var reader = (SqlDataReader)ConnectSource.ExecuteReader(pSqlCommand))
                {
                    if (reader.HasRows)
                    {
                        using (var bulkCopy = new SqlBulkCopy(ConnectTarget.Connection, pBulkConfig.Options, null))
                        {
                            bulkCopy.SqlRowsCopied       += BulkCopy_SqlRowsCopied;
                            bulkCopy.NotifyAfter          = 1;
                            bulkCopy.BulkCopyTimeout      = pBulkConfig.CopyTimeout;
                            bulkCopy.BatchSize            = pBulkConfig.BatchSize;
                            bulkCopy.DestinationTableName = pNomeTabela;
                            bulkCopy.WriteToServer(reader);
                        }
                    }

                    reader.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(_rowsCopied);
        }
예제 #2
0
        public void Disconnect()
        {
            if (_connectSource != null)
            {
                ConnectSource.Disconnect();
            }

            if (_connectTarget != null)
            {
                ConnectTarget.Disconnect();
            }
        }
예제 #3
0
        public Dictionary <string, string> GetTables()
        {
            DataSet ds = ConnectSource.ExecuteDataset(Properties.Resources.get_tables);
            Dictionary <string, string> ret = new();

            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    ret.Add(dr[0].ToString(), dr[1].ToString());
                }
            }

            return(ret);
        }
예제 #4
0
        public string GerarScriptInsert(string pNomeTabela)
        {
            IDataReader dr = null;

            try
            {
                dr = ConnectSource.ExecuteReader(string.Format("SELECT * FROM {0} WITH(NOLOCK)", pNomeTabela));

                string result = "";
                string values;
                string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Insert");

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                path = Path.Combine(path, pNomeTabela + ".sql");

                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                using (StreamWriter sw = new(path, false, Encoding.ASCII))
                {
                    while (dr.Read())
                    {
                        values = "";
                        for (int i = 0; i < dr.FieldCount; i++)
                        {
                            if (!object.ReferenceEquals(dr[i], DBNull.Value))
                            {
                                values += "," + GetFormatDataValue(dr[i].GetType(), dr[i].ToString());
                            }
                            else
                            {
                                values += ", NULL";
                            }
                        }
                        if (result != "")
                        {
                            result += ", (" + values[1..] + ")" + Environment.NewLine;