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; }
/// <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; }