internal static IResolvedDataSource ElementToObject(RdlDataSource dataSourceElement, ReportMeta reportMeta)
        {
            if (dataSourceElement.ConnectionProperties == null)
            {
                // Probably a data source reference. The user should resolve these themselves.
                // But if not, give them a null object. If it's never referenced, there's no problem.
                return(null);
            }

            if (dataSourceElement.ConnectionProperties == null)
            {
                // Again, if there's no connection string the user should have resolved
                // this data source themselves. But if not, give them a null object.
                return(null);
            }

            Type resolverType;

            lock (DataSourceResolvers)
                if (!DataSourceResolvers.TryGetValue(dataSourceElement.ConnectionProperties.DataProvider, out resolverType))
                {
                    return(null);
                }

            IResolvedDataSource resolved = null;

            try
            {
                resolved = (IResolvedDataSource)Activator.CreateInstance(resolverType);
                resolved.Initialize(dataSourceElement, reportMeta);
            }
            catch (Exception)
            {
                if (resolved != null)
                {
                    resolved.Dispose();
                }

                throw;
            }

            return(resolved);
        }
예제 #2
0
        public void Initialize(RdlDataSource dataSourceElement, ReportMeta reportMeta)
        {
            DataSourceElement = dataSourceElement;
            ReportMeta        = reportMeta;
            IsTransactional   = LocalReportsEngineCommon.StringToBool(dataSourceElement.Transaction);

            string factoryName;

            lock (DbFactoryNames)
                if (!DbFactoryNames.TryGetValue(dataSourceElement.ConnectionProperties.DataProvider, out factoryName))
                {
                    throw new ArgumentOutOfRangeException("dataSourceElement",
                                                          "ConnectionProperties.DataProvider is unknown");
                }

            var providerFactory  = DbProviderFactories.GetFactory(factoryName);
            var connectionString = CreateConnectionString(dataSourceElement, providerFactory);

            AdHocConnection       = CreateConnection(providerFactory, connectionString);
            TransactionConnection = IsTransactional ? CreateConnection(providerFactory, connectionString) : null;
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="providerFactory"></param>
        /// <returns></returns>
        private static string CreateConnectionString(RdlDataSource dataSource, DbProviderFactory providerFactory)
        {
            var genericConnectionStringBuilder = providerFactory.CreateConnectionStringBuilder();

            Debug.Assert(genericConnectionStringBuilder != null, "genericConnectionStringBuilder != null");
            genericConnectionStringBuilder.ConnectionString = dataSource.ConnectionProperties.ConnectString;

            var sqlConnectionStringBuilder = genericConnectionStringBuilder as SqlConnectionStringBuilder;

            if (sqlConnectionStringBuilder != null)
            {
                bool integratedSecurity;
                if (Boolean.TryParse(dataSource.ConnectionProperties.IntegratedSecurity, out integratedSecurity) &&
                    integratedSecurity)
                {
                    sqlConnectionStringBuilder.IntegratedSecurity = true;
                    sqlConnectionStringBuilder.UserID             = String.Empty;
                    sqlConnectionStringBuilder.Password           = String.Empty;
                }
            }

            return(genericConnectionStringBuilder.ConnectionString);
        }
        internal static IResolvedDataSource ElementToObject(RdlDataSource dataSourceElement, ReportMeta reportMeta)
        {
            if (dataSourceElement.ConnectionProperties == null)
                // Probably a data source reference. The user should resolve these themselves.
                // But if not, give them a null object. If it's never referenced, there's no problem.
                return null;

            if (dataSourceElement.ConnectionProperties == null)
                // Again, if there's no connection string the user should have resolved
                // this data source themselves. But if not, give them a null object.
                return null;

            Type resolverType;
            lock (DataSourceResolvers)
                if (!DataSourceResolvers.TryGetValue(dataSourceElement.ConnectionProperties.DataProvider, out resolverType))
                    return null;

            IResolvedDataSource resolved = null;

            try
            {
                resolved = (IResolvedDataSource) Activator.CreateInstance(resolverType);
                resolved.Initialize(dataSourceElement, reportMeta);
            }
            catch (Exception)
            {
                if (resolved != null)
                    resolved.Dispose();

                throw;
            }

            return resolved;
        }