Пример #1
0
        public static IEnumerable <string> TabloOlustur(DbServer kaynakServer, DbServer hedefServer, IEnumerable <string> tablolar)
        {
            Server _server = new Server(kaynakServer.Ip);

            _server.ConnectionContext.LoginSecure = kaynakServer.LoginSecure;

            if (!kaynakServer.LoginSecure)
            {
                _server.ConnectionContext.Login    = kaynakServer.Username;
                _server.ConnectionContext.Password = kaynakServer.Password;
            }
            _server.ConnectionContext.Connect();

            string   database = kaynakServer.Database;
            Scripter scripter = new Scripter(_server);
            Database _db      = _server.Databases[database];
            var      sqlCodes = new List <string>();

            foreach (string tablo in tablolar)
            {
                foreach (string script in _db.Tables[tablo].Script())
                {
                    sqlCodes.Add(script);
                }

                foreach (Index index in _db.Tables[tablo].Indexes)
                {
                    foreach (string script in index.Script())
                    {
                        sqlCodes.Add(script);
                    }
                }

                foreach (Trigger trigger in _db.Tables[tablo].Triggers)
                {
                    foreach (string script in trigger.Script())
                    {
                        sqlCodes.Add(script);
                    }
                }
            }
            return(SqlExec(hedefServer, sqlCodes));
        }
Пример #2
0
        public FrmMain()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;

            ToolTip toolTip = new ToolTip();

            toolTip.SetToolTip(this.btnTabloTumunuSec, "Tümünü Seç");
            toolTip.SetToolTip(this.btnKolonTumunuSec, "Tümünü Seç");
            toolTip.SetToolTip(this.btnPFTumunuSec, "Tümünü Seç");
            toolTip.SetToolTip(this.btnViewTumunuSec, "Tümünü Seç");
            toolTip.SetToolTip(this.btnTabloAktar, "Seçilenleri Aktar");
            toolTip.SetToolTip(this.btnKolonAktar, "Seçilenleri Aktar");
            toolTip.SetToolTip(this.btnPFAktar, "Seçilenleri Aktar");
            toolTip.SetToolTip(this.btnViewAktar, "Seçilenleri Aktar");

            kaynakServer = new DbServer();
            hedefServer  = new DbServer();

            cboKaynakAuthType.SelectedIndex = 0;
            cboHedefAuthType.SelectedIndex  = 0;
        }
Пример #3
0
        public static bool BaglantiTest(DbServer server, ComboBox cbo)
        {
            cbo.Items.Clear();
            using (var conn = new SqlConnection())
            {
                try
                {
                    conn.ConnectionString = server.ConnectionString;
                    conn.Open();
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = @"SELECT name
                                        FROM sys.databases
                                        WHERE name NOT IN (
		                                        'master'
		                                        ,'tempdb'
		                                        ,'model'
		                                        ,'msdb'
		                                        )"        ;

                        SqlDataReader dr = cmd.ExecuteReader();
                        while (dr.Read())
                        {
                            cbo.Items.Add(dr["name"].ToString());
                        }
                        dr.Close();
                        conn.Close();
                        return(true);
                    }
                }
                catch
                {
                    return(false);
                }
            }
        }
Пример #4
0
        public static List <Table> TabloVeKolonlariGetir(DbServer server)
        {
            using (var conn = new SqlConnection())
            {
                conn.ConnectionString = server.ConnectionString;
                conn.Open();
                var liste    = new List <TableProperties>();
                var tablolar = new List <Table>();
                using (var cmd = conn.CreateCommand())
                {
                    string database = server.Database;
                    cmd.CommandText = $"USE [{database}]";
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = $@"SELECT Tablolar.TABLE_NAME
	                                        ,Columns.COLUMN_NAME
	                                        ,Columns.DATA_TYPE
	                                        ,Columns.CHARACTER_MAXIMUM_LENGTH
	                                        ,Columns.IS_NULLABLE
                                        FROM INFORMATION_SCHEMA.TABLES AS Tablolar
                                        INNER JOIN INFORMATION_SCHEMA.COLUMNS AS Columns ON Tablolar.TABLE_NAME = Columns.TABLE_NAME
                                        WHERE Tablolar.TABLE_TYPE = 'BASE TABLE'
                                        ORDER BY Tablolar.TABLE_NAME ASC";

                    SqlDataReader dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        var tkm = new TableProperties();
                        tkm.TABLE_NAME  = dr["TABLE_NAME"].ToString();
                        tkm.COLUMN_NAME = dr["COLUMN_NAME"].ToString();
                        tkm.DATA_TYPE   = dr["DATA_TYPE"].ToString();
                        tkm.IS_NULLABLE = dr["IS_NULLABLE"].ToString();
                        tkm.CHARACTER_MAXIMUM_LENGTH = dr["CHARACTER_MAXIMUM_LENGTH"].ToString();
                        liste.Add(tkm);
                    }

                    liste.ForEach(item =>
                    {
                        if (!tablolar.Any(m => m.Name == item.TABLE_NAME))
                        {
                            var tbl  = new Table();
                            tbl.Name = item.TABLE_NAME;
                            tablolar.Add(tbl);
                        }
                    });

                    tablolar.ForEach(m =>
                    {
                        m.Columns = new List <Column>();
                        liste.Where(k => k.TABLE_NAME == m.Name).ToList().ForEach(k =>
                        {
                            var kolon  = new Column();
                            kolon.Name = k.COLUMN_NAME;

                            kolon.Type = k.CHARACTER_MAXIMUM_LENGTH != null &&
                                         k.CHARACTER_MAXIMUM_LENGTH != "-1" &&
                                         k.CHARACTER_MAXIMUM_LENGTH != ""
                        ? k.DATA_TYPE + " (" + k.CHARACTER_MAXIMUM_LENGTH + ")"
                        : k.DATA_TYPE;


                            if (k.IS_NULLABLE == "NO")
                            {
                                kolon.Type += " NOT NULL";
                            }
                            m.Columns.Add(kolon);
                        });
                    });

                    dr.Close();
                    conn.Close();
                    return(tablolar);
                }
            }
        }