Ok so this is really becoming frustrating and am hoping that someone can help me with this. I have just started going through some SignalR tutorials and all of that was working great. Then I decided to add an MVC Entity Framework model for some data access to my SignalR project so I could store name and messages that have been send to my test chat message hub.
Here is the frustrating part, this all works great when I run in debug from Visual Studio but as soon as I publish to my IIS server the Entity Framework code in my message hub stops working and throws this Error: ProviderIncompatibleException
Inner Exception:
"{"An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct."}"
Next Inner Exception:
{"The provider did not return a ProviderManifestToken string."}
Last Inner Exception:
{"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Error occurred during LocalDB instance startup: SQL Server process failed to start.\r\n)"}
This error is thrown on the "db.Database.Initialize(false);" line in my message hub code.
This was frustrating me so much that I was researching these error messages last night until 1:00 am. I would really appreciate ANY help with this. And the most frustrating thing is this code is so simple it should just be working......
Thanks.
Here is the code for my message hub:
public class BPACustomerServiceMessageHub : Hub
{
public void Send(string name, string message)
{
Database.SetInitializer(new CreateDatabaseIfNotExists<MessagesContext>());
using (MessagesContext db = new MessagesContext())
{
db.Database.Initialize(false);
Messages omsg = new Messages();
omsg.name = name;
omsg.message = message;
db.Messages.Add(omsg);
db.SaveChanges();
db.Dispose();
}
// Call the broadcastMessage method to update clients.
Clients.All.broadcastMessage(name, message);
SendParams mparams = new SendParams();
mparams.Name = name;
mparams.Message = message;
Clients.All.broadcastMessage2(mparams);
}
}
public class SendParams
{
public string Name { get; set; }
public string Message { get; set; }
}
Here is the code for my model and context:
public class Messages
{
[Key]
public int id { get; set; }
public string name { get; set; }
public string message { get; set; }
}
public class MessagesContext : DbContext
{
public DbSet<Messages> Messages { get; set; }
}
Here is my connection string from my web.config:
<connectionStrings>
<add name="MessagesContext"
connectionString="Data Source=(LocalDB)\v11.0;
database=Messages;
AttachDbFilename=|DataDirectory|\Messages.mdf;
Initial Catalog=Messages;
Integrated Security=True"
providerName="System.Data.SqlClient" />