private RemoteSqlClient(string connectionString, ChannelFactory <ISqlProxy> proxyChannelFactory, bool disposeChannelFactory) { if (connectionString == null) { throw new ArgumentNullException(nameof(connectionString)); } if (proxyChannelFactory == null) { throw new ArgumentNullException(nameof(proxyChannelFactory)); } try { // When the proxy records the requests and responses in cache, it records the connection string so that it can compare it to the connection string of // future requests, for cases where the requests should be fulfilled by the cached data - if the connection strings are not consistent then the cache // data is not considered to be applicable. However, when SQL Server Authentication is used (when a username and password are part of the connection // string), the ConnectionString property of a SqlConnection will not report the password that was part of the connection string used in configuring // the connection - this results in a discrepancy, meaning that cached entries are never matched. The workaround is to enable the PersistSecurityInfo // option in the connection string for cases where Windows Authentication is not used, this prevents the password from being hidden when the Connection // String property is retrieved from a SqlConnection. Since this service should only be used internally, in particular test environments, this minor // relaxing of security should not be a concern (and it will be a non-issue if Windows Authentication is used, which is the recommended approach). var connectionStringDetails = new SqlConnectionStringBuilder(connectionString); if (!connectionStringDetails.IntegratedSecurity && !connectionStringDetails.PersistSecurityInfo) { connectionStringDetails.PersistSecurityInfo = true; connectionString = connectionStringDetails.ToString(); } } catch { // There is nothing that REQUIRES us to be talking a SQL Server instance (it could be a Sqlite database that we'll be talking to, for example) - so, // if we couldn't parse the connection using the SqlConnectionStringBuilder class then don't worry about it } try { _disposeChannelFactory = disposeChannelFactory; _proxyChannelFactory = proxyChannelFactory; _proxy = _proxyChannelFactory.CreateChannel(); ((ICommunicationObject)_proxy).Faulted += SetFaulted; _connection = new RemoteSqlConnectionClient(_proxy, connectionId: _proxy.GetNewConnectionId()); _connection.ConnectionString = connectionString; } catch { Dispose(true); throw; } _faulted = false; _disposed = false; }
public Host(ISqlProxy singleInstanceContextModeProxy, Binding binding, Uri endPoint, Action <Exception> optionalErrorLogger = null) { if (singleInstanceContextModeProxy == null) { throw new ArgumentNullException(nameof(singleInstanceContextModeProxy)); } if (binding == null) { throw new ArgumentNullException(nameof(binding)); } if (endPoint == null) { throw new ArgumentNullException(nameof(endPoint)); } try { _host = new ServiceHost(singleInstanceContextModeProxy); _host.AddServiceEndpoint(typeof(ISqlProxy), binding, endPoint); _host.Faulted += SetFaulted; _host.Description.Behaviors.Remove(typeof(ServiceDebugBehavior)); _host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); _host.Description.Behaviors.Add(new ErrorWrappingBehavior(optionalErrorLogger)); _host.Open(); } catch { Dispose(); throw; } _faulted = false; _disposed = false; }
public Host(ISqlProxy singleInstanceContextModeProxy, Uri endPoint, Action <Exception> optionalErrorLogger = null) : this(singleInstanceContextModeProxy, GetDefaultBinding(), endPoint, optionalErrorLogger) { }
public RemoteSqlConnectionClient(ISqlProxy proxy, ConnectionId connectionId) : this(proxy, proxy, proxy, proxy, proxy, proxy, connectionId) { }