You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

EntityFramework DB First报错‘Keyword not supported: 'port'’求解决

解决EntityFramework DB First生成模型时“Keyword not supported: 'port'”错误

这个错误核心原因是连接字符串格式与你使用的EF数据库提供者不匹配,以下是具体解决步骤:

  • 确认数据库类型及对应EF提供者

    • 若使用SQL Server:SQL Server连接字符串无需单独写port参数,自定义端口直接追加在服务器名后用逗号分隔,格式示例:
      Server=localhost,1435;Database=YourDatabase;User Id=sa;Password=yourPassword;
      
    • 若使用MySQL:需先安装适配的EF提供者(如MySql.EntityFrameworkCore),连接字符串中Port参数是合法的,格式示例:
      Server=localhost;Port=3306;Database=YourDatabase;Uid=root;Pwd=yourPassword;
      
  • 修正Scaffold命令中的连接字符串
    根据数据库类型调整命令,示例如下:

    • SQL Server对应的Scaffold命令:
      Scaffold-DbContext "Server=localhost,1433;Database=TestDB;User Id=sa;Password=123456;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
      
    • MySQL对应的Scaffold命令:
      Scaffold-DbContext "Server=localhost;Port=3306;Database=TestDB;Uid=root;Pwd=123456;" MySql.EntityFrameworkCore -OutputDir Models
      
  • 额外排查点

    • 检查连接字符串是否拼写错误,比如参数大小写误用(虽多数情况不敏感,但个别场景会触发问题)
    • 避免混用不同数据库的连接字符串规则,比如SQL Server不要加Port参数,MySQL不要用Server=xxx,端口的写法

内容的提问来源于stack exchange,提问作者JH. Lee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 06:40:53