SQL Server and EF Migration from local to remote database

c# entity-framework-6 sql-server tsql visual-studio-2012


I'm working on an Entity Framework (EF) project that functions as a supplemental class library to another project within my Visual Studio 2013 solution. I initially had a mock local database on my client dev system and build out the schema and other utilities from there. The data adapter I'm using uses SQL Authentication.

Once I had a validated stable build that satisfied my requirements, I incorporated the EF project into the solution. Working off of the local database, everything worked fine. I then re-aimed the EF database to a remote SQL server by:

  1. Updating my Data adapter to the remote server
  2. Successfully testing my data adapter's connection
  3. updating the App.Config files in the start-up project and the EF project with the correct connection string
  4. Ran the T-SQL script generated by EF on the remote server
  5. Validated that the T-SQL script worked by observing the database view and seeing my new tables present

Once I finished, I re-ran the solution. EF threw an exception on the first call from the Framework:

An unhandled exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlServer.dll

Additional information: The underlying provider failed on Open.

When I checked the inner-exception, I found this:

Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

This exception puzzles me because if you'll recall at the beginning of my post, I'm using SQL authentication.

I'm currently not using anything ASP.NET related, my testbed is simply being executed from a console application which had no problems pre-migration.

I want to say this is an administration/environment issue, not code because locally I have no issues and my T-SQL script seems to run fine on the remote server, and I have connectivity with it. Unfortunately for me my SQL server skills are no where near my coding ability, I'm unable to "prove" it. So I find myself at a loss.

Any help would from the fine folks at stackoverflow would be appreciated!


Per DrewJordan:

Context Constructor -

public DatabaseContext(): base("name=DatabaseContext") {}

Connection String -

connectionString="metadata=res:///Database.csdl|res:///Database.ssdl|res://*/Database.msl;provider=System.Data.SqlClient;provider connection string="data source=mycompany.com\SQLEXPRESS;initial catalog=sandbox2_db;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"

1/5/2016 8:55:14 PM

Accepted Answer

I found the problem. As I said before, my project uses SQL authentication, but if you notice in my connection string there is no SQL user ID.

Entity Framework will use the local client user ID by default if no user ID has been provided.

The later is qualified within the remote domain, the local client is not, which is why I fail to connect.

1/8/2016 6:06:12 PM

Popular Answer

You have turned windows authentication on by this setting integrated security=True; change it to integrated security=False; or you can remove that field altogether.

Source: 2 hours of bug hunting on a past project. here is the msdn reference

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow