/// <summary>
        /// 确认 <paramref name="x"/> 所表示的数据库连接字符串与 <paramref name="y"/> 所表示的数据库连接字符串是否表示同一个数据库连接。
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public override bool Equals(string x, string y)
        {
            x = Check.EmptyCheck(x);
            y = Check.EmptyCheck(y);

            DbConnectionStringBuilder a = this.ProviderFactory.CreateConnectionStringBuilder();

            a.ConnectionString = x;

            DbConnectionStringBuilder b = this.ProviderFactory.CreateConnectionStringBuilder();

            b.ConnectionString = y;

            if (this.ProviderFactory is System.Data.SqlClient.SqlClientFactory)
            {
                var m = a as System.Data.SqlClient.SqlConnectionStringBuilder;
                var n = b as System.Data.SqlClient.SqlConnectionStringBuilder;
                if (m != null && n != null)
                {
                    return(string.Equals(m.DataSource, n.DataSource, StringComparison.OrdinalIgnoreCase)
                           //&& string.Equals(m.UserID, n.UserID, StringComparison.OrdinalIgnoreCase)
                           //&& string.Equals(m.Password, n.Password, StringComparison.OrdinalIgnoreCase)
                           && string.Equals(m.InitialCatalog, n.InitialCatalog, StringComparison.OrdinalIgnoreCase));
                    //&& m.PersistSecurityInfo == n.PersistSecurityInfo
                    //&& m.ApplicationIntent == n.ApplicationIntent
                    //&& string.Equals(m.NetworkLibrary, n.NetworkLibrary, StringComparison.OrdinalIgnoreCase);
                }
            }

            return(a.EquivalentTo(b));
        }
예제 #2
0
        IConnectionStringProvider CreateConfigPerEndpointConnectionStringProvider(LocalConnectionParams localConnectionParams)
        {
            const string transportConnectionStringPrefix = "NServiceBus/Transport/";
            var          configConnectionStrings         =
                connectionStrings
                .Where(x => x.Name.StartsWith(transportConnectionStringPrefix))
                .Select(x =>
            {
                string schema;
                var connectionString = x.ConnectionString.ExtractSchemaName(out schema);
                var endpoint         = x.Name.Replace(transportConnectionStringPrefix, String.Empty);
                var connectionInfo   = EndpointConnectionInfo.For(endpoint).UseSchema(schema);

                var localConnectionStringBuilder = new DbConnectionStringBuilder {
                    ConnectionString = localConnectionParams.ConnectionString
                };
                var overriddenConnectionStringBuilder = new DbConnectionStringBuilder {
                    ConnectionString = connectionString
                };

                if (!localConnectionStringBuilder.EquivalentTo(overriddenConnectionStringBuilder))
                {
                    connectionInfo = connectionInfo.UseConnectionString(connectionString);
                }
                return(connectionInfo);
            })
                .ToArray();

            return(new CollectionConnectionStringProvider(configConnectionStrings, localConnectionParams));
        }
예제 #3
0
        /// <summary>
        /// 是否需要更新,当连接不一样才进行重新更改连接
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="connectionString"></param>
        private bool IsNeedUpdate(string connectionString)
        {
            DbConnectionStringBuilder sourceConn = new DbConnectionStringBuilder();

            sourceConn.ConnectionString = "";// MasterConnectionString;

            DbConnectionStringBuilder newConn = new DbConnectionStringBuilder();

            newConn.ConnectionString = connectionString;

            return(!sourceConn.EquivalentTo(newConn));
        }
        /// <summary>
        /// 判断数据库连接 是否一致
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="connectionString"></param>
        /// <returns>true:一致</returns>
        private bool ConnectionStringCompare(DbConnection conn, string connectionString)
        {
            DbProviderFactory factory = DbProviderFactories.GetFactory(conn);

            DbConnectionStringBuilder a = factory.CreateConnectionStringBuilder();

            a.ConnectionString = conn.ConnectionString;

            DbConnectionStringBuilder b = factory.CreateConnectionStringBuilder();

            b.ConnectionString = connectionString;

            return(a.EquivalentTo(b));
        }
예제 #5
0
파일: source.cs 프로젝트: ruo2012/samples-1
        // <Snippet1>
        static void Main()
        {
            DbConnectionStringBuilder builder1 =
                new DbConnectionStringBuilder();

            builder1.ConnectionString =
                "Value1=SomeValue;Value2=20;Value3=30;Value4=40";
            Console.WriteLine("builder1 = " + builder1.ConnectionString);

            DbConnectionStringBuilder builder2 =
                new DbConnectionStringBuilder();

            builder2.ConnectionString =
                "value2=20;value3=30;VALUE4=40;Value1=SomeValue";
            Console.WriteLine("builder2 = " + builder2.ConnectionString);

            DbConnectionStringBuilder builder3 =
                new DbConnectionStringBuilder();

            builder3.ConnectionString =
                "value2=20;value3=30;VALUE4=40;Value1=SOMEVALUE";
            Console.WriteLine("builder3 = " + builder3.ConnectionString);

            // builder1 and builder2 contain the same
            // keys and values, in different order, and the
            // keys are not consistently cased. They are equivalent.
            Console.WriteLine("builder1.EquivalentTo(builder2) = " +
                              builder1.EquivalentTo(builder2).ToString());

            // builder2 and builder3 contain the same key/value pairs in the
            // the same order, but the value casing is different, so they're
            // not equivalent.
            Console.WriteLine("builder2.EquivalentTo(builder3) = " +
                              builder2.EquivalentTo(builder3).ToString());

            Console.WriteLine("Press Enter to continue.");
            Console.ReadLine();
        }