简体   繁体   English

从本地数据库到远程数据库的SQL Server和EF迁移

[英]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服务器:

  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 使用正确的连接字符串更新启动项目和EF项目中的App.Config文件
  4. Ran the T-SQL script generated by EF on the remote server 在远程服务器上运行EF生成的T-SQL脚本
  5. Validated that the T-SQL script worked by observing the database view and seeing my new tables present 通过观察数据库视图并查看我的新表来验证T-SQL脚本是否有效

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.

相关问题 同步两个本地和远程SQL Server数据库 - sync two local and remote sql server database 如何在不使用复制的情况下将本地 SQL 服务器数据库的数据同步到远程 SQL 服务器? - How to synchronize data from local SQL Server database to remote SQL Server without using replication? 如何在远程ms sql server上更新数据库(EF Code First) - How to update database on remote ms sql server (EF Code First) 从Windows命令提示符运行本地SQL脚本文件以更新远程SQL Server数据库 - Run local SQL script file from Windows Command Prompt to update remote SQL Server database EF同步节省本地和远程数据库 - EF synchronic savings of local and remote database 如何将远程SQL Server Express数据库部分复制到本地SQL Server Express数据库? - How to do a partial copy of a remote SQL Server Express database to a local SQL Server Express database? 将远程SQL Server数据库与本地SQL Server Compact数据库同步的最佳方法? - Best way to sync remote SQL Server database with local SQL Server Compact database? 将 EF6 数据库优先从 SQL Server 迁移到 PostgreSQL - Migrate EF6 database-first from SQL Server to PostgreSQL 从本地MDF到SQL Server应用程序的迁移 - Local MDF to SQL Server Application Migration EF 迁移中的原始 SQL - Raw SQL in EF migration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM