Exemplo n.º 1
0
        public bool Test()
        {
            var s = string.Format("Data Source={0}; User ID='{1}'; Password='******'; Initial Catalog='{3}';", Server, Username, Password, Database);
            var c = new SqlConnection(s);

            try
            {
                c.Open();
                if (c.State == System.Data.ConnectionState.Open)
                {
                    c.Close();
                    c.Dispose();
                    return(true);
                }

                else
                {
                    c.Dispose();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                XtraMsg.Error(ex.Message);
                return(false);
            }
        }
Exemplo n.º 2
0
        private void BtnAttach_Click(object sender, EventArgs e)
        {
            if (db == null)
            {
                XtraMsg.Error("CONNECTION MUST ESTABLISTED FIRST!");
                return;
            }

            db.Attach();
        }
Exemplo n.º 3
0
        private void BtnDetach_Click(object sender, EventArgs e)
        {
            if (db == null)
            {
                XtraMsg.Error("CONNECTION MUST ESTABLISTED FIRST!");
                return;
            }

            txtMdfLoc.Text = db.GetMDF();
            txtLdfLoc.Text = db.GetLDF();

            db.Detach();
        }
Exemplo n.º 4
0
        private void BtnConn_Click(object sender, EventArgs e)
        {
            con          = new Conn();
            con.Database = txtDb.Text;
            con.Server   = txtServer.Text;
            con.Username = txtUser.Text;
            con.Password = txtPass.Text;

            if (!con.Test())
            {
                XtraMsg.Warn("CANT CONNECT TO SERVER!");
                return;
            }
            else
            {
                XtraMsg.Info("CONNECTED TO SERVER!");
            }

            db = new Database(con);
        }
Exemplo n.º 5
0
        public string GetMDF()
        {
            q = string.Format("SELECT type,physical_name FROM sys.database_files WHERE type=0");
            var dt = script.Run(q, "DT");

            if (dt == null)
            {
                XtraMsg.Error("DATABASE PHYSICAL DB FILE CANNOT BE FOUND!");
                return("");
            }

            if (dt.Rows.Count <= 0)
            {
                XtraMsg.Error("DATABASE PHYSICAL DB FILE CANNOT BE FOUND!");
                return("");
            }

            this.PhysicalMDF = Utils.Clean(dt.Rows[0][1]);

            return(this.PhysicalMDF);
        }
Exemplo n.º 6
0
        public bool Run(string q)
        {
            try
            {
                if (sqlCon.State != ConnectionState.Open)
                {
                    sqlCon.Open();
                }


                var cmd = new SqlCommand(q, sqlCon);
                cmd.ExecuteNonQuery();
                sqlCon.Close();
                cmd.Dispose();
                return(true);
            }
            catch (Exception ex)
            {
                XtraMsg.Error(ex.Message);
                return(false);
            }
        }