Entity Framework 6.0.3 problem
-
I have an C# Windows Forms application (let's call it "APP-A") that I use on a weekly basis. I've been using APP-A for a while and recently needed to add the ability to store data into a MS-SQL database. So I added EntityFramework 6.1.3 to my project (using NuGet) and using Code First, I quickly added my model classes and a dbcontext class, targeting my local SQLEXPRESS instance. All works, life is good, the data I need to store is in the DB, success! Next, I needed to move my SQL DB to one of our MSSQL servers, so I changed the connection string in App.config and ran the application, expecting the DB would be created on the server. The DB was not created so I manually created the DB on the server, then ran the application and it won't connect to the server DB. I then changed the connection string back to point to my local SQLEXPRESS, and the application again works perfectly. Frustrated, I created a brand new C# console app (lets call it "APP-B") and added EF 6.1.3 to it, then copied my models and dbcontext classes and connection string from APP-A to APP-B and attempted to connect to the DB on the server, which APP-B did without a problem. I then deleted the DB from the server, re-ran APP-B and the database was recreated correctly on the server. I changed APP-B connection string to point to my local SQLEXPRESS and it connected to the local DB fine, then I changed the APP-B connection string to point at the server and it again works fine. So now I have two projects, APP-A which will connect to my local SQLEXPRESS but not the server, and APP-B which can access BOTH the server DB and the local SQLEXPRESS DB. I cannot emphasize this enough: both APP-A and APP-B contain the same models and dbcontext classes as well as the same connection strings. Today I removed and reinstalled EF 6.1.3 from APP-A and I still get the same results - APP-A can access the local SQLEXPRESS DB, but not the server DB. Has anyone ever seen this behavior before?
Sincerely, -Mark mamiller@rhsnet.org
-
I have an C# Windows Forms application (let's call it "APP-A") that I use on a weekly basis. I've been using APP-A for a while and recently needed to add the ability to store data into a MS-SQL database. So I added EntityFramework 6.1.3 to my project (using NuGet) and using Code First, I quickly added my model classes and a dbcontext class, targeting my local SQLEXPRESS instance. All works, life is good, the data I need to store is in the DB, success! Next, I needed to move my SQL DB to one of our MSSQL servers, so I changed the connection string in App.config and ran the application, expecting the DB would be created on the server. The DB was not created so I manually created the DB on the server, then ran the application and it won't connect to the server DB. I then changed the connection string back to point to my local SQLEXPRESS, and the application again works perfectly. Frustrated, I created a brand new C# console app (lets call it "APP-B") and added EF 6.1.3 to it, then copied my models and dbcontext classes and connection string from APP-A to APP-B and attempted to connect to the DB on the server, which APP-B did without a problem. I then deleted the DB from the server, re-ran APP-B and the database was recreated correctly on the server. I changed APP-B connection string to point to my local SQLEXPRESS and it connected to the local DB fine, then I changed the APP-B connection string to point at the server and it again works fine. So now I have two projects, APP-A which will connect to my local SQLEXPRESS but not the server, and APP-B which can access BOTH the server DB and the local SQLEXPRESS DB. I cannot emphasize this enough: both APP-A and APP-B contain the same models and dbcontext classes as well as the same connection strings. Today I removed and reinstalled EF 6.1.3 from APP-A and I still get the same results - APP-A can access the local SQLEXPRESS DB, but not the server DB. Has anyone ever seen this behavior before?
Sincerely, -Mark mamiller@rhsnet.org
SOLVED! The problem was caused by WHERE my APP-A project was located. At my work we have shared user folders that are hosted on the network, and that is where my APP-A project was located. The problem with that is that these shared folders are not trusted by our SQL servers, so when my application ran from that location the SQL server would reject the connection. I just moved my project to my local C: drive, rebuilt it and ran it and viola! it connects to the SQL server database without issue. My APP-B project was created on my local C: drive which is why it was able to access both the local SQLEXPRESS and the SQL server databases without issue.
Sincerely, -Mark mamiller@rhsnet.org