Пример #1
0
 static ShardMapUtils()
 {
     // Connection resiliency is supported if this SqlClient instance
     // allows setting the retry count on connection failure
     SqlConnectionStringBuilder bldr = new SqlConnectionStringBuilder();
     if (bldr.ContainsKey(ConnectRetryCount))
     {
         IsConnectionResiliencySupported = true;
     }
 }
		public void ContainsKeyTest ()
		{
			builder = new SqlConnectionStringBuilder ("SERVER=localhost;Network=DBMSSOCN");
			Assert.AreEqual (true, builder.ContainsKey ("NETWORK"),
					 "#CKT1 should say true");
			Assert.AreEqual (false, builder.ContainsKey ("ABCD"),
					 "#CKT2 should say false");
		}
        /// <summary>
        /// Ensures that credentials are provided for the given connection string object.
        /// </summary>
        /// <param name="connectionString">Input connection string object.</param>
        /// <param name="parameterName">Parameter name of the connection string object.</param>
        internal static void EnsureCredentials(SqlConnectionStringBuilder connectionString, string parameterName)
        {
            // Check for integrated authentication
            if (connectionString.IntegratedSecurity)
            {
                return;
            }

            // Check for active directory integrated authentication (if supported)
            if (connectionString.ContainsKey(ShardMapUtils.Authentication) &&
                connectionString[ShardMapUtils.Authentication].ToString().Equals(ShardMapUtils.ActiveDirectoryIntegratedStr))
            {
                return;
            }

            // UserID must be set when integrated authentication is disabled.
            if (string.IsNullOrEmpty(connectionString.UserID))
            {
                throw new ArgumentException(
                    StringUtils.FormatInvariant(
                        Errors._SqlShardMapManagerCredentials_ConnectionStringPropertyRequired,
                        "UserID"),
                    parameterName);
            }

            // Password must be set when integrated authentication is disabled.
            if (string.IsNullOrEmpty(connectionString.Password))
            {
                throw new ArgumentException(
                    StringUtils.FormatInvariant(
                        Errors._SqlShardMapManagerCredentials_ConnectionStringPropertyRequired,
                        "Password"),
                    parameterName);
            }
        }