private SqlConnectionString(SqlConnectionString value) : base(value, false) { // Clone
            _permission = value._permission;

            _integratedSecurity = value._integratedSecurity;
            _connectionReset = value._connectionReset;
            _enlist = value._enlist;
            _encrypt = value._encrypt;
            _persistSecurityInfo = value._persistSecurityInfo;
            _pooling = value._pooling;

            _connectionLifeTime = value._connectionLifeTime;
            _connectTimeout = value._connectTimeout;
            _maxPoolSize = value._maxPoolSize;
            _minPoolSize = value._minPoolSize;
            _packetSize = value._packetSize;

            _applicationName = value._applicationName;
            _attachDBFileName = value._attachDBFileName;
            _currentLanguage = value._currentLanguage;
            _dataSource = value._dataSource;
            _initialCatalog = value._initialCatalog;
            _networkLibrary = value._networkLibrary;
            _userID = value._userID;
            _password = value._password;
            _workstationId = value._workstationId;
        }
        private SqlConnectionString(string connectionString) : base(connectionString, UdlSupport.ThrowIfFound) {
#endif
            if (base.IsEmpty()) {
                _integratedSecurity  = DEFAULT.Integrated_Security;
                _connectionReset     = DEFAULT.Connection_Reset;
                _enlist              = DEFAULT.Enlist;
                _encrypt             = DEFAULT.Encrypt;
                _persistSecurityInfo = DEFAULT.Persist_Security_Info;
                _pooling             = DEFAULT.Pooling;

                _connectionLifeTime = DEFAULT.Connection_Lifetime;
                _connectTimeout     = DEFAULT.Connect_Timeout;
                _maxPoolSize        = DEFAULT.Max_Pool_Size;
                _minPoolSize        = DEFAULT.Min_Pool_Size;
                _packetSize         = DEFAULT.Packet_Size;

                _applicationName  = DEFAULT.Application_Name;
                _attachDBFileName = DEFAULT.AttachDBFilename;
                _currentLanguage  = DEFAULT.Current_Language;
                _dataSource       = DEFAULT.Data_Source;
                _initialCatalog   = DEFAULT.Initial_Catalog;
                _networkLibrary   = DEFAULT.Network_Library;
                _userID           = DEFAULT.User_ID;
                _password         = DEFAULT.Password;
                _workstationId    = _workstation_ID;
            }
            _permission = new SqlClientPermission(this);
        }
		public void None ()
		{
			SqlClientPermission perm = new SqlClientPermission (PermissionState.None);
			Check ("None-1", perm, false, false, 0);
			perm.AllowBlankPassword = true;
			Check ("None-2", perm, true, false, 0);

			SqlClientPermission copy = (SqlClientPermission)perm.Copy ();
			Check ("Copy_None-1", copy, true, false, 0);
			copy.AllowBlankPassword = false;
			Check ("Copy_None-2", copy, false, false, 0);
		}
Example #4
0
 public bool CanRequestNotifications()
 {
     try
     {
         SqlClientPermission perm = new SqlClientPermission(PermissionState.Unrestricted);
         perm.Demand();
         return true;
     }
     catch
     {
         return false;
     }
 }
Example #5
0
 public Pedido()
 {
     InitializeComponent();
     try
     {
         SqlClientPermission perm = new SqlClientPermission(PermissionState.Unrestricted);
         perm.Demand();
     }
     catch
     {
         throw new ApplicationException("No tiene permisos de notificación");
     }
 }
Example #6
0
 static private bool EnoughPermission()
 {
     SqlClientPermission perm = new SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted);
     try
     {
         perm.Demand();
         return true;
     } 
     catch (System.Exception)
     {
         return false;
     }
 }
		public void None_Childs ()
		{
			SqlClientPermission perm = new SqlClientPermission (PermissionState.None);
			perm.Add ("data source=localhost;", String.Empty, KeyRestrictionBehavior.AllowOnly);
			perm.Add ("data source=127.0.0.1;", "password=;", KeyRestrictionBehavior.PreventUsage);

			Check ("None-Childs-1", perm, false, false, 2);
			perm.AllowBlankPassword = true;
			Check ("None-Childs-2", perm, true, false, 2);

			SqlClientPermission copy = (SqlClientPermission)perm.Copy ();
			Check ("Copy_None-Childs-1", copy, true, false, 2);
			copy.AllowBlankPassword = false;
			Check ("Copy_None-Childs-2", copy, false, false, 2);
		}
Example #8
0
        private bool CanRequestNotifications()
        {
            // In order to use the callback feature of the
            // SqlDependency, the application must have
            // the SqlClientPermission permission.
            try
            {
                SqlClientPermission perm =
                    new SqlClientPermission(
                    PermissionState.Unrestricted);

                perm.Demand();

                return true;
            }
            catch
            {
                return false;
            }
        }
Example #9
0
        //private Thread myThread;
        //Initialize
        public HostingForm()
        {
            InitializeComponent();

            _rkApp.SetValue("Vents service", Application.ExecutablePath);

            try
            {
                var perm = new SqlClientPermission(PermissionState.Unrestricted);
                perm.Demand();
            }
            catch
            {
                throw new ApplicationException("No permission");
            }

            CheckPdmVault();

            Program.HostForm = this;
        }
 internal static bool HasSqlClientPermission()
 {
     NamedPermissionSet namedPermissionSet = HttpRuntime.NamedPermissionSet;
     if (namedPermissionSet == null)
     {
         return true;
     }
     IPermission target = namedPermissionSet.GetPermission(typeof(SqlClientPermission));
     if (target == null)
     {
         return false;
     }
     IPermission permission2 = null;
     try
     {
         permission2 = new SqlClientPermission(PermissionState.Unrestricted);
     }
     catch
     {
         return false;
     }
     return permission2.IsSubsetOf(target);
 }
Example #11
0
        internal static bool HasSqlClientPermission() {
            NamedPermissionSet  permissionset = HttpRuntime.NamedPermissionSet;
            
            // If we don't have a NamedPermissionSet, we're in full trust
            if (permissionset == null)
                return true;

            // Check that the user has unrestricted SqlClientPermission
            IPermission allowedPermission = permissionset.GetPermission(typeof(SqlClientPermission));

            if (allowedPermission == null) {
                return false;
            }
            
            IPermission askedPermission = null;
            try {
                askedPermission = new SqlClientPermission(PermissionState.Unrestricted);
            }
            catch {
                return false;
            }
            
            return askedPermission.IsSubsetOf(allowedPermission);
        }
 private void EnsureSqlDependencyListening()
 {
     if (!_sqlDependencyListenerStarted)
     {
         lock (_ensureSqlDependencyListeningLocker)
         {
             if (!_sqlDependencyListenerStarted)
             {
                 SqlDependency.Start(ConnectionString);
                 var perm = new SqlClientPermission(PermissionState.Unrestricted);
                 perm.Demand();
                 _sqlDependencyListenerStarted = true;
             }
         }
     }
 }
Example #13
0
 public static bool DoesUserHavePermission()
 {
     try
     {
         SqlClientPermission clientPermission = new SqlClientPermission(PermissionState.Unrestricted);
         clientPermission.Demand();
         return true;
     }
     catch
     {
         return false;
     }
 }
 private SqlClientPermission(SqlClientPermission permission) : base(permission) { // for Copy
 }
		public void Unrestricted ()
		{
			SqlClientPermission perm = new SqlClientPermission (PermissionState.Unrestricted);
			Check ("Unrestricted-1", perm, false, true, 0);
			perm.AllowBlankPassword = true;
			Check ("Unrestricted-2", perm, true, true, 0);

			SqlClientPermission copy = (SqlClientPermission)perm.Copy ();
			// note: Unrestricted is always created with default values (so AllowBlankPassword is false)
			Check ("Copy_Unrestricted-1", copy, false, true, 0);
			copy.AllowBlankPassword = true;
			Check ("Copy_Unrestricted-2", copy, true, true, 0);
		}
Example #16
0
 private void InitSqlDependency()
 {
     LazyInitializer.EnsureInitialized(ref _sqlDependencyInit, () =>
         {
             SqlDependency.Start(_connectionString);
             var perm = new SqlClientPermission(PermissionState.Unrestricted);
             perm.Demand();
             return new object();
         });
 }
    private void StartNotifyConnection()
    {
        _sqlConn = new SqlConnection(_connectString);

        // check if hosting enviromnet can listen to exceptions
        SqlClientPermission perm =new SqlClientPermission(PermissionState.Unrestricted);

        try
        {
            perm.Demand();
        }
        catch (Exception ex)
        {
            var secEx = new Exception("The hosting enviromnent does not have SqlClientPermission",ex);
            broadCastException(secEx);
            throw secEx;
        }

        try
        {
            _sqlConn.Open();
            SqlDependency.Stop(_connectString);
            SqlDependency.Start(_connectString);
            StartNotifying();
        }
        catch (Exception ex)
        {
            broadCastException(ex);
            throw;
        }
    }
Example #18
0
        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            SqlClientPermission pSql = new SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted);
            pSql.Assert();

            string connectionStringName = config["connectionStringName"];
            if (string.IsNullOrEmpty(connectionStringName))
            {
                throw new ProviderException("Connection string not specified");
            }

            this.connectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;

            base.Initialize(name, config);
        }
		public void PermissionState_Invalid ()
		{
			PermissionState ps = (PermissionState)Int32.MinValue;
			SqlClientPermission perm = new SqlClientPermission (ps);
		}
		public void Unrestricted_Add ()
		{
			SqlClientPermission perm = new SqlClientPermission (PermissionState.Unrestricted);
			Check ("Unrestricted-NoChild", perm, false, true, 0);
			perm.Add ("data source=localhost;", String.Empty, KeyRestrictionBehavior.AllowOnly);
			// note: Lost unrestricted state when children was added
			Check ("Unrestricted-WithChild", perm, false, false, 1);
		}
 static internal void Demand(SqlConnectionString constr) {
     SqlClientPermission permission = ((null != constr) ? constr._permission : SqlConnection.SqlClientPermission);
     permission.Demand();
 }
Example #22
0
 private SqlClientPermission(SqlClientPermission permission) : base(permission)
 {
 }
 private SqlClientPermission(SqlClientPermission permission) : base(permission)   // for Copy
 {
 }
 private SqlClientPermission(SqlClientPermission permission) : base(permission)
 {
 }
Example #25
0
        private bool DoesUserHavePermission()
        {
            try
            {
                SqlClientPermission clientPermission = new SqlClientPermission(PermissionState.Unrestricted);

                // will throw an error if user does not have permissions
                clientPermission.Demand();

                return true;
            }
            catch
            {
                return false;
            }
        }