gpt4 book ai didi

c# - Entity Framework 连接字符串问题

转载 作者:太空狗 更新时间:2023-10-29 18:19:20 24 4
gpt4 key购买 nike

我正在制作一个小库 (DLL) 来管理用户及其角色/权限。计划是能够将此 dll 添加到 MVC 项目并能够操作用户/角色/等。所有数据都驻留在 SQL 数据库中。

我正在使用 Entity Framework 进行数据访问。

因此,当我初始化一个新的 RoleManager(这是我正在制作的库中主类的名称)时,我为它提供了一个 connectionString,如下所示:

RoleManager roleManager = new RoleManager(string connectionString);

然后在构造函数中我这样做:

db = new RoleManagerEntities(connectionString); //This is the EntityFramework

我正在尝试提供此连接字符串(以及许多其他字符串)

"metadata=res://*/RoleManager.csdl|res://*/RoleManager.ssdl|res://*/RoleManager.msl;provider=System.Data.SqlClient;provider connection string='Data Source=localhost;Initial Catalog=Login;Integrated Security=True;Connection Timeout=60; multipleactiveresultsets=true'"

我收到以下错误:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

这个问题是由于尝试从我的新项目实例化 EF 而没有提供连接字符串并且我的应用程序配置中没有任何默认设置的结果。太糟糕了,我现在不能删除它。

最佳答案

只需将连接字符串信息从 DLL 配置文件复制到可执行配置文件即可。

关于c# - Entity Framework 连接字符串问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3962805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com