Posted on 15/05/2017 08:50:45
Hi Nicolai,
Hmm it seems to work okay on most pages, also in the backend. However, on some pages I get the error below. Also, in the backend, under Repositories, I can't see any indices. Seems that indexing still relies on global settings for accessing the database? We're running 9.2.10 in this case.
System.Data.SqlClient.SqlException (0x80131904): Login failed for user ''.
ved System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)
ved System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
ved System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
ved System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
ved System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
ved System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
ved System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
ved System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
ved System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
ved System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
ved System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
ved System.Data.SqlClient.SqlConnection.Open()
ved Dynamicweb.Ecommerce.Indexing.ProductIndexSchemaExtender.GetFields()
ved Dynamicweb.Indexing.Schemas.ExtensionFieldDefinition.GetFields()
ved Dynamicweb.Indexing.IndexHelper.ConvertToIndex(XElement obj)
ved Dynamicweb.Indexing.IndexService.LoadIndex(String name)
ved Dynamicweb.Indexing.Queries.IndexQueryProvider.Query(IQuery query, QuerySettings settings)
ved Dynamicweb.Ecommerce.Frontend.Frontend.GetProductsFromIndexQuery() ClientConnectionId:f05dd8fb-86b4-48d4-af61-d4ffbd55a2fa Error Number:18456,State:1,Class:14
I have removed database information from globalsettings file, as it should not be needed there if we are to trust a web transform using the class you provided. With small changes, we ended up with:
public class DatabaseConnectionProvider : IDatabaseConnectionProvider
{
public virtual IDbConnection CreateConnection()
{
var connectionString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
IDbConnection tmpDbConnection = new SqlConnection(connectionString);
try
{
tmpDbConnection.Open();
}
catch
{
tmpDbConnection.Dispose();
throw;
}
return tmpDbConnection;
}
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Because IDbDataAdapter is not disposable.")]
public virtual IDbDataAdapter CreateAdapter()
{
return new SqlDataAdapter();
}
}