• 0

SQLDependency, SignalR & Entity Framework Code First


Question

Is anyone here experienced with SQLDependency, SignalR and Entity Framework's code first model?

 

I'm currently developing an MVC website with a SQL Server backend and am using EF6 for the the ORM. I need to implement push notifications so that users are notified of certain events.

 

Now, I have all this working just fine. Users are getting their notifications and everything is behaving as it should except when, in the development environment only, a change is made to one of the database tables.

 

In the normal course of events with Code First, a change to an entity causes the database to be dropped and re-created, and the Seed method reran to populate with my test data, however since implementing push notifications this is no longer working and I get the following error in my Application_Start method of Global.asax.cs.

 

Quote

Additional information: Cannot open database "xxxxx" requested by the login. The login failed.

Login failed for user 'xxxxxxxx'.

 

The error happens when it hits the following line (con is my connection string).

SqlDependency.Start(con);

 

Obviously, this is wigging out because the database has been dropped and will be created so there are no logins for it yet (using Windows Authentication), but why hasn't the damned thing created the new one by now?  The Database.SetInitializer is right at the top of the method and surely it should have gotten it done by the time it tries to start the SqlDependency?  I feel that I'm missing something here...

 

This is the first time I've tried using SignalR, so do I have to run the SqlDependency.Start() method in Application_Start, or can it be run from somewhere else that doesn't fire until AFTER the new DB is created?  It's rather a pain in the backside to have to disable this code whenever I have a table change (which is often right now), and 2 days of trawling through Goggle hasn't found a damned thing...

 

Anyone?

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.