【发布时间】:2022-12-23 11:39:19
【问题描述】:
我正在试验 Maui Blazor。 我想将我的应用程序与 SQL 服务器数据库连接。 因此我使用了一个简单的 Sql 连接字符串。 当我用“普通 Windows 机器”测试它时没有问题,但是当我想在 android 模拟器上测试它时它不工作。
我使用了“scaffold-DBContext ..”命令并在生成的方法中包含了我的连接字符串:
...
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
var sqlConnectionString = ...;
//#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
optionsBuilder.UseSqlServer(sqlConnectionString);
}
...
我必须做什么才能在 android 模拟器上运行? 我在“OnConfiguring”方法中的断点甚至没有被击中(使用 Android)。
(也许有人知道为什么它不起作用?)
非常感谢你提前
【问题讨论】:
-
当您执行“dotnet ef add migrations >name<”时,迁移过程会调用 OnConfiguration 方法。如何在 Android 环境中使用 scaffold-DBContext?你想从 Android 模拟器调用“添加迁移”吗?你想达到什么目的?
-
您确定模拟器可以连接到 SQL Server 数据库吗?连接字符串是否使用主机名? DNS 名称? IP地址?
-
@Cleptus 我不知道模拟器是否有 Sql 服务器连接。我怎样才能测试它? “Windows 机器”可以连接但不能连接 android 模拟器。目前我在 connectionString 中使用 IP 地址
标签: c# android sql-server maui-blazor