Ejemplo n.º 1
0
        internal static bool CanCreateAndOpenConnection(
            StoreSchemaConnectionFactory connectionFactory, string providerInvariantName, string designTimeInvariantName,
            string designTimeConnectionString)
        {
            Debug.Assert(connectionFactory != null, "connectionFactory != null");
            Debug.Assert(
                !string.IsNullOrWhiteSpace(designTimeInvariantName),
                "designTimeInvariantName must not be null or empty");
            Debug.Assert(
                !string.IsNullOrWhiteSpace(designTimeConnectionString),
                "designTimeConnectionString must not be null or empty");

            EntityConnection entityConnection = null;

            try
            {
                // attempt to create a DbConnection using the provider connection string we have. This will
                // throw an exception if the connection cannot be made, for example, if the credentials aren't
                // set. This has to be done using DDEX-based APIs since the SchemaGenerator is based off of
                // DbConnection, and DDEX will save the password whereas DbConnection will not.
                Version _;
                entityConnection = connectionFactory.Create(
                    DependencyResolver.Instance,
                    providerInvariantName,
                    designTimeConnectionString,
                    EntityFrameworkVersion.Latest,
                    out _);
                entityConnection.Open();
            }
            catch
            {
                return(false);
            }
            finally
            {
                // Close the EntityConnection
                if (entityConnection != null)
                {
                    VsUtils.SafeCloseDbConnection(entityConnection, designTimeInvariantName, designTimeConnectionString);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        // internal virtual for testing
        internal virtual StoreSchemaDetails GetStoreSchemaDetails(StoreSchemaConnectionFactory connectionFactory)
        {
            Version storeSchemaModelVersion;
            var     connection =
                connectionFactory
                .Create(
                    DependencyResolver.Instance,
                    _settings.RuntimeProviderInvariantName,
                    _settings.DesignTimeConnectionString,
                    _settings.TargetSchemaVersion,
                    out storeSchemaModelVersion);

            var facadeFilters =
                _settings.DatabaseObjectFilters ?? Enumerable.Empty <EntityStoreSchemaFilterEntry>();

            return
                (CreateDbSchemaLoader(connection, storeSchemaModelVersion)
                 .LoadStoreSchemaDetails(facadeFilters.ToList()));
        }