Particular/Workshop

.\SQLEXPRESS instance is used insted (localdb)\microservices-workshop in exercise 02

bryjamus opened this issue · 10 comments

In https://github.com/Particular/Workshop/tree/master/exercises/02-publish-subscribe/before exercise insted of (localdb)\microservices-workshop in connection string in finance service is use .\SQLEXPRESS. This issue is in Divergent.Finance.Handlers.OrderSubmittedHandler.Handle method (FinanceContext has wrong connection string). In all app.config there are proper connection strings and I can find place where connection string is replaced.

@bryjamus thanks for raising this.
I checked and the expected connection string is defined in the app.config file in both before and after solutions.

E.g. https://github.com/Particular/Workshop/blob/master/exercises/02-publish-subscribe/before/Divergent.Finance/App.config

Can you please provide more details about the error/behavior your facing?

@mauroservienti I know that app.configs has proper connection strings. But in this exercise database connection string for financial context is different. I don't know what change it. We try to find it with @tmasternak. What about nHibernate - is it possible that it changes connection string?

That’s weird. We’re not using NHibernate, but Entity Framework. With Entity Framework what can cause that behavior if the convention used to find the connection string fails.
When opening a DbContext without specifying a connection string EF looks for a connection string in the app.config file whose name matches the DbContext name. In our case the context is named FinanceContext and the connection string uses the same name. When the 2 don’t match EF uses it’s default data source, that IIRC is .\SqlExpress.

Are you by any chance, while playing with it, changing some code?

Sorry, I mean EF not NH. I change code as described in exercise. With @tmasternak we've checked names and connection string and it looks ok but in debug database has wrong connection string. I'll try find when or what change connection string and let you know.

If you search for SQLEXPRESS with GitHub search, it can't find any results. I'm not an expert at search, not even with Google, but perhaps you could specify the project, file and/or line number?
Curious case! :-)

I've try to figure it out but I have something wrong with pdb for EntityFramework (Symbols loaded but shows disassmbled code). But I've found that wrong connection string instance is set when there is call stack like this:

System.Data.dll!System.Data.SqlClient.SqlConnection.ConnectionString.set(string value)	Unknown	Symbols loaded.
EntityFramework.dll!System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.SetConnectionString.AnonymousMethod__18(System.Data.Common.DbConnection t, System.Data.Entity.Infrastructure.Interception.DbConnectionPropertyInterceptionContext<string> c)
EntityFramework.dll!System.Data.Entity.Infrastructure.Interception.InternalDispatcher<System.Data.Entity.Infrastructure.Interception.IDbConnectionInterceptor>.Dispatch<System.Data.Common.DbConnection, System.Data.Entity.Infrastructure.Interception.DbConnectionPropertyInterceptionContext<string>>(System.Data.Common.DbConnection target, System.Action<System.Data.Common.DbConnection, System.Data.Entity.Infrastructure.Interception.DbConnectionPropertyInterceptionContext<string>> operation, System.Data.Entity.Infrastructure.Interception.DbConnectionPropertyInterceptionContext<string> interceptionContext, System.Action<System.Data.Entity.Infrastructure.Interception.IDbConnectionInterceptor, System.Data.Common.DbConnection, System.Data.Entity.Infrastructure.Interception.DbConnectionPropertyInterceptionContext<string>> executing, System.Action<System.Data.Entity.Infrastructure.Interception.IDbConnectionInterceptor, System.Data.Common.DbConnection, System.Data.Entity.Infrastructure.Interception.DbConnectionPropertyInterceptionContext<string>> executed)
EntityFramework.dll!System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.SetConnectionString(System.Data.Common.DbConnection connection, System.Data.Entity.Infrastructure.Interception.DbConnectionPropertyInterceptionContext<string> interceptionContext)
EntityFramework.dll!System.Data.Entity.Infrastructure.SqlConnectionFactory.CreateConnection(string nameOrConnectionString)
EntityFramework.dll!System.Data.Entity.Internal.LazyInternalConnection.Initialize()
EntityFramework.dll!System.Data.Entity.Internal.LazyInternalConnection.ProviderName.get()
EntityFramework.dll!System.Data.Entity.Internal.LazyInternalContext.ProviderName.get()
EntityFramework.dll!System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create(System.Data.Entity.DbContext context)
EntityFramework.dll!System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
EntityFramework.dll!System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(System.Type entityType)
EntityFramework.dll!System.Data.Entity.Internal.Linq.InternalSet<Divergent.Finance.Data.Models.Price>.Initialize()
EntityFramework.dll!System.Data.Entity.Internal.Linq.InternalSet<Divergent.Finance.Data.Models.Price>.InternalContext.get()
EntityFramework.dll!System.Data.Entity.Infrastructure.DbQuery<Divergent.Finance.Data.Models.Price>.System.Linq.IQueryable.Provider.get()
System.Core.dll!System.Linq.Queryable.Where<Divergent.Finance.Data.Models.Price>(System.Linq.IQueryable<Divergent.Finance.Data.Models.Price> source, System.Linq.Expressions.Expression<System.Func<Divergent.Finance.Data.Models.Price, bool>> predicate)
Divergent.Finance.exe!Divergent.Finance.Handlers.OrderSubmittedHandler.Handle(Divergent.Sales.Messages.Events.OrderSubmittedEvent message, NServiceBus.IMessageHandlerContext context)

So I can't check what set this value but maybe it will help you to figure out what is wrong.

@bryjamus Thanks, any idea which exercise it is? Before or after folder?

This line sets the connectionstring : https://github.com/Particular/Workshop/blob/master/exercises/02-publish-subscribe/before/Divergent.Finance.Data/Context/FinanceContext.cs#L9
This is the host : https://github.com/Particular/Workshop/tree/master/exercises/02-publish-subscribe/before/Divergent.Customers
This is the connectionstring it's reading : https://github.com/Particular/Workshop/blob/master/exercises/02-publish-subscribe/before/Divergent.Finance/App.config#L8

I took before folder from Exercise 04 but it could be another exercise.
It could also be another host that's causeing the issue, although since it's a handler, I doubt that's possible.

Could you please clean your solution, see if all .dll and .pdb files are gone? And then do full rebuild?

This is exercise 02 (publisher-subscriber) before solution. I've cleaned solutrion, remove bin and obj folders, recompile and the same issue occurs. This shows when in UI click in Orders button and then Add new order.

@bryjamus I'm closing this because we've run the workshop several times since February and no-one else has come across a similar problem in that time. If you're still having problems then please feel free to re-open this issue or raise a new one.

Thanks again for raising this issue.