gpt4 book ai didi

Azure 错误 - 连接字符串困难

转载 作者:行者123 更新时间:2023-12-02 23:19:10 24 4
gpt4 key购买 nike

我正在 vs 2015 中使用 mvc5 应用程序。每当我尝试从数据库访问项目时都会收到错误

Login failed for user '{your_username}'.

当我进入 Azure 门户时,“允许访问 Azure 服务”设置已打开,并列出了我的客户端 IP 地址。我认为我的连接字符串配置不正确。我不知道如何在本地计算机上使用 azure 正确配置它。

我已将网络配置中的连接字符串保留到之前运行过的本地服务器:

在我的 web.config 中

<add name="IdentityDbContext" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=C:\Users\UserName\EduSmart_db.Mdf;          Initial Catalog=EduSmart_db;Integrated Security=True" providerName="System.Data.SqlClient" />

在 Azure 门户连接字符串中

Server=tcp:xxxx.database.windows.net,1433;Initial Catalog=Edu;Persist Security Info=False;User ID=Name;Password=Password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
  • 如何判断 azure 正在使用哪个连接字符串?
  • 还有其他问题我没有考虑过吗?

最佳答案

How can I tell which connection string azure is using?

Azure 使用第二个连接字符串。第一个(localdb)刚刚在本地计算机中使用。服务器无法获取它。您可以在 Context 类中添加 Azure Sql 连接字符串名称来指定它。

Is there a different problem i have not considered?

您可以通过以下方式查看:

1.Azure Sql Database中的防火墙设置。你可以定义一个 IP地址范围(如×.×.×.0到×.×.×.255)而不是只有一个IP 地址。

enter image description here

2.您可以在 web.configs 文件中检查 Azure sql 连接字符串,例如 这。在我这边效果很好。

 <connectionStrings>
<add name="ConnectionStringName" providerName="System.Data.SqlClient" connectionString="Data Source=tcp:[databasename].database.windows.net,1433;Initial Catalog=[databasename];Integrated Security=False;User Id=[username];Password=[password];Encrypt=True;TrustServerCertificate=False;MultipleActiveResultSets=True" />
</connectionStrings>

如果您使用 Code First for Azure Sql,您可以在 Context 类中添加相关的连接字符串名称:

 public ApplicationDbContext(): base("ConnectionStringName")
{
}

3.您可以点击工具>连接到数据库>Microsoft SQL 服务器输入您的Azure服务器名称、用户名和密码 sql。然后点击测试连接按钮检查是否可以成功连接。

enter image description here

另外,你可以引用这个article了解如何在本地访问项目中的 Azure Sql。

关于Azure 错误 - 连接字符串困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49184932/

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