private Connection GetConnection(SqlServerServiceInfo info, IConfiguration configuration) { var sqlConfig = new SqlServerProviderConnectorOptions(configuration); var configurer = new SqlServerProviderConfigurer(); return(new Connection(configurer.Configure(info, sqlConfig), "SqlServer", info)); }
private static void DoAdd(IServiceCollection services, SqlServerServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime) { var sqlServerConfig = new SqlServerProviderConnectorOptions(config); var factory = new SqlServerProviderConnectorFactory(info, sqlServerConfig, SqlServerTypeLocator.SqlConnection); services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RelationalHealthContributor((IDbConnection)factory.Create(ctx), ctx.GetService <ILogger <RelationalHealthContributor> >()), contextLifetime)); }
public void UpdateConfiguration(SqlServerServiceInfo si, SqlServerProviderConnectorOptions configuration) { if (si == null) { return; } if (!string.IsNullOrEmpty(si.Uri)) { configuration.Port = si.Port; configuration.Server = si.Host; if (!string.IsNullOrEmpty(si.Path)) { configuration.Database = si.Path; } if (si.Query != null) { foreach (var piece in si.Query.Split('&')) { var kvp = piece.Split('='); if (kvp[0].EndsWith("database", StringComparison.InvariantCultureIgnoreCase) || kvp[0].EndsWith("databaseName", StringComparison.InvariantCultureIgnoreCase)) { configuration.Database = kvp[1]; } else if (kvp[0].EndsWith("instancename", StringComparison.InvariantCultureIgnoreCase)) { configuration.InstanceName = kvp[1]; } else if (kvp[0].StartsWith("hostnameincertificate", StringComparison.InvariantCultureIgnoreCase)) { // adding this key could result in "System.ArgumentException : Keyword not supported: 'hostnameincertificate'" later } else { configuration.Options.Add(kvp[0], kvp[1]); } } } if (configuration.UrlEncodedCredentials) { configuration.Username = WebUtility.UrlDecode(si.UserName); configuration.Password = WebUtility.UrlDecode(si.Password); } else { configuration.Username = si.UserName; configuration.Password = si.Password; } } }
private static void DoAdd(IServiceCollection services, SqlServerServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, bool addSteeltoeHealthChecks) { var sqlServerConnection = SqlServerTypeLocator.SqlConnection; var sqlServerConfig = new SqlServerProviderConnectorOptions(config); var factory = new SqlServerProviderConnectorFactory(info, sqlServerConfig, sqlServerConnection); services.Add(new ServiceDescriptor(typeof(IDbConnection), factory.Create, contextLifetime)); services.Add(new ServiceDescriptor(sqlServerConnection, factory.Create, contextLifetime)); if (!services.Any(s => s.ServiceType == typeof(HealthCheckService)) || addSteeltoeHealthChecks) { services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RelationalDbHealthContributor((IDbConnection)factory.Create(ctx), ctx.GetService <ILogger <RelationalDbHealthContributor> >()), ServiceLifetime.Singleton)); } }
public Connection Get(IConfiguration configuration, string serviceName) { var info = serviceName == null ? configuration.GetSingletonServiceInfo <SqlServerServiceInfo>() : configuration.GetRequiredServiceInfo <SqlServerServiceInfo>(serviceName); var sqlConfig = new SqlServerProviderConnectorOptions(configuration); var configurer = new SqlServerProviderConfigurer(); return(new Connection { ConnectionString = configurer.Configure(info, sqlConfig), Name = "SqlServer" + serviceName?.Insert(0, "-") }); }
public void UpdateConfiguration(SqlServerServiceInfo si, SqlServerProviderConnectorOptions configuration) { if (si == null) { return; } if (!string.IsNullOrEmpty(si.Uri)) { configuration.Port = si.Port; configuration.Server = si.Host; if (!string.IsNullOrEmpty(si.Path)) { configuration.Database = si.Path; } if (si.Query != null) { foreach (var kvp in UriExtensions.ParseQuerystring(si.Query)) { if (kvp.Key.EndsWith("database", StringComparison.InvariantCultureIgnoreCase) || kvp.Key.EndsWith("databaseName", StringComparison.InvariantCultureIgnoreCase)) { configuration.Database = kvp.Value; } else if (kvp.Key.EndsWith("instancename", StringComparison.InvariantCultureIgnoreCase)) { configuration.InstanceName = kvp.Value; } else if (kvp.Key.StartsWith("hostnameincertificate", StringComparison.InvariantCultureIgnoreCase)) { // adding this key could result in "System.ArgumentException : Keyword not supported: 'hostnameincertificate'" later } else { configuration.Options.Add(kvp.Key, kvp.Value); } } } configuration.Username = si.UserName; configuration.Password = si.Password; } }
public string Configure(SqlServerServiceInfo si, SqlServerProviderConnectorOptions configuration) { UpdateConfiguration(si, configuration); return(configuration.ToString()); }
public SqlServerProviderConnectorFactory(SqlServerServiceInfo sinfo, SqlServerProviderConnectorOptions config, Type type) { _config = config ?? throw new ArgumentNullException(nameof(config)); _info = sinfo; ConnectorType = type; }