Esempio n. 1
0
        private T QuerySysTable <T>(string col, string table, string where, params string[] args)
        {
            var cmd = (SqlCommand)SchemaConnection.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = string.Format("SELECT {0} FROM sys.{1} WHERE {2}", col, table, where);

            for (var i = 0; i < args.Length; i++)
            {
                cmd.Parameters.Add("@p" + (i + 1), SqlDbType.Char, args[i].Length).Value = args[i];
            }

            var openClose = SchemaConnection.State == ConnectionState.Closed;

            if (openClose)
            {
                SchemaConnection.Open();
            }

            try
            {
                return((T)cmd.ExecuteScalar());
            }
            finally
            {
                if (openClose)
                {
                    SchemaConnection.Close();
                }
            }
        }
Esempio n. 2
0
        private string GetCreateStatement(string dbobject)
        {
            var cmd = (SqlCommand)SchemaConnection.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "SELECT OBJECT_DEFINITION(OBJECT_ID(@p1));";
            cmd.Parameters.Add("@p1", SqlDbType.Char, dbobject.Length).Value = dbobject;

            bool openClose = SchemaConnection.State == ConnectionState.Closed;

            if (openClose)
            {
                SchemaConnection.Open();
            }

            try
            {
                var create = cmd.ExecuteScalar();
                if (create is DBNull)
                {
                    return(string.Format("CREATE [{0}] AS FAILED TO IMPORT", dbobject));
                }
                return((string)create);
            }
            finally
            {
                if (openClose)
                {
                    SchemaConnection.Close();
                }
            }
        }
Esempio n. 3
0
        private T QuerySysTable <T>(string col, string table, string where, params string[] args)
        {
            SqlCommand cmd = (SqlCommand)SchemaConnection.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = string.Format("SELECT {0} FROM sys.{1} WHERE {2}", col, table, where);

            for (int i = 0; i < args.Length; i++)
            {
                cmd.Parameters.Add("@p" + (i + 1), SqlDbType.Char, args[i].Length).Value = args[i];
            }

            return((T)cmd.ExecuteScalar());
        }