[英]SQL Server and EF Migration from local to remote database
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. 我正在开发一个实体框架(EF)项目,该项目充当Visual Studio 2013解决方案中另一个项目的补充类库。 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.
我正在使用的数据适配器使用SQL身份验证。
Once I had a validated stable build that satisfied my requirements, I incorporated the EF project into the solution. 一旦我拥有经过验证的,可以满足我的要求的稳定版本,便将EF项目合并到解决方案中。 Working off of the local database, everything worked fine.
在本地数据库上工作,一切正常。 I then re-aimed the EF database to a remote SQL server by:
然后,我通过以下方法将EF数据库重新命名为远程SQL服务器:
App.Config
files in the start-up project and the EF project with the correct connection string App.Config
文件 Once I finished, I re-ran the solution. 完成后,我重新运行该解决方案。 EF threw an exception on the first call from the Framework:
EF在框架的首次调用中引发了异常:
An unhandled exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlServer.dll
类型的未处理的异常“System.Data.Entity.Core.EntityException”发生在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.
该登录名来自不受信任的域,不能与Windows身份验证一起使用。
This exception puzzles me because if you'll recall at the beginning of my post, I'm using SQL authentication. 此异常使我感到困惑,因为如果您在文章开头回忆起,我正在使用SQL身份验证。
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. 我目前未使用任何与ASP.NET相关的东西,我的测试床只是从控制台应用程序执行的,该控制台应用程序在迁移前没有问题。
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. 我想说的是这是一个管理/环境问题,而不是代码问题,因为在本地没有问题,而且我的T-SQL脚本似乎可以在远程服务器上正常运行,并且可以与之连接。 Unfortunately for me my SQL server skills are no where near my coding ability, I'm unable to "prove" it.
不幸的是,我的SQL Server技能远不及我的编码能力,我无法“证明”它。 So I find myself at a loss.
所以我发现自己茫然。
Any help would from the fine folks at stackoverflow would be appreciated! 在stackoverflow上的优秀人员提供的任何帮助将不胜感激!
Appended: 附加:
Per DrewJordan: 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" connectionString =“ metadata = res:// /Database.csdl|res:// /Database.ssdl|res://*/Database.msl;provider=System.Data.SqlClient;provider连接字符串=” data source = mycompany .com \\ SQLEXPRESS;初始目录= sandbox2_db;集成安全性= True; MultipleActiveResultSets = True; App = EntityFramework“” providerName =“ System.Data.EntityClient”
You have turned windows authentication on by this setting integrated security=True;
您已通过此设置启用 Windows身份验证
integrated security=True;
change it to integrated security=False;
将其更改为
integrated security=False;
or you can remove that field altogether. 或者您可以完全删除该字段。
Source: 2 hours of bug hunting on a past project. 资料来源:在过去的项目中需要2个小时的bug搜索。 here is the msdn reference
这是msdn参考
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.
如前所述,我的项目使用SQL身份验证,但是如果您在连接字符串中注意到没有SQL用户ID。
Entity Framework will use the local client user ID by default if no user ID has been provided. 如果未提供用户ID,则Entity Framework默认将使用本地客户端用户ID。
The later is qualified within the remote domain, the local client is not, which is why I fail to connect. 后者在远程域中是合格的,而本地客户端则不是,这就是为什么我无法连接的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.