Adds a new connection string and a set of restricted keywords to the SqlClientPermission object.
Namespace:
System.Data.SqlClient
Assembly:
System.Data (in System.Data.dll)
Visual Basic (Declaration)
Public Overrides Sub Add ( _
connectionString As String, _
restrictions As String, _
behavior As KeyRestrictionBehavior _
)
Dim instance As SqlClientPermission
Dim connectionString As String
Dim restrictions As String
Dim behavior As KeyRestrictionBehavior
instance.Add(connectionString, restrictions, _
behavior)
public override void Add(
string connectionString,
string restrictions,
KeyRestrictionBehavior behavior
)
public:
virtual void Add(
String^ connectionString,
String^ restrictions,
KeyRestrictionBehavior behavior
) override
public override function Add(
connectionString : String,
restrictions : String,
behavior : KeyRestrictionBehavior
)
Use this method to configure which connection strings are allowed by a particular permission object. For example, use the following code fragment if you want to only allow a specific connection string and nothing else:
permission.Add("server=MyServer; database=MyDatabase; Integrated Security=true", "", KeyRestrictionBehavior.AllowOnly)
The following example allows connection strings that use any database, but only on the server named MyServer, with any user and password combination and containing no other connection string keywords:
permission.Add("server=MyServer;", "database=; user id=; password=;", KeyRestrictionBehavior.AllowOnly)
The following example uses the same scenario as above but allows for a failover partner that can be used when connecting to servers configured for mirroring:
permission.Add("server=MyServer; failover partner=MyMirrorServer", "database=; user id=; password=;”, KeyRestrictionBehavior.AllowOnly)
Note: |
|---|
When using code access security permissions for ADO.NET, the correct pattern is to start with the most restrictive case (no permissions at all) and then add the specific permissions that are needed for the particular task that the code needs to perform. The opposite pattern, starting with all permissions and then trying to deny a specific permission, is not secure, because there are many ways of expressing the same connection string. For example, if you start with all permissions and then attempt to deny the use of the connection string "server=someserver", the string "server=someserver.mycompany.com" would still be allowed. By always starting by granting no permissions at all, you reduce the chances that there are holes in the permission set. |
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1
Reference
Other Resources