Azure错误-连接字符串困难 [英] Azure error - connection string difficulties

查看:57
本文介绍了Azure错误-连接字符串困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vs 2015中的mvc5应用程序. 每当我尝试访问数据库中的项目时都会出现错误

I am working with an mvc5 application in vs 2015. I am getting errors whenever I attempt to access items from the database

用户'{your_username}'登录失败.

Login failed for user '{your_username}'.

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

When I go azure portal "allow access to azure services" setting is on with my client Ip address listed. I think my connection string is not configured correctly. I can't figure out how to correctly configure it on my local machine and with azure.

我已将连接字符串保留在我以前可以正常使用的本地服务器的Web配置中:

I have kept my the connection string in my web config to my local server which worked previously:

在我的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 Portal连接字符串中

In Azure Portal connection string

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使用的是哪个连接字符串?
  • 我没有考虑过其他问题吗?
  • 推荐答案

    我怎么知道azure在使用哪个连接字符串?

    How can I tell which connection string azure is using?

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

    Azure use the second connection string. The first one(localdb) just used in your local machine. The server can not get it. You could add Azure Sql connection string name in Context class to specific it.

    我没有考虑过其他问题吗?

    Is there a different problem i have not considered?

    您可以通过以下方式进行检查:

    You could check from these ways:

    1. Azure Sql数据库.哟可以定义一个 ip地址范围(例如×.×.×.0到×.×.×.255),而不是一个ip 地址.

    1.The firewall settings in Azure Sql Database. Yo could define a range of ip address(like ×.×.×.0 to ×.×.×.255) instead of only one ip address.

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

    2.You could check Azure sql connection string in web.configs file like this. It works fine on my side.

     <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用于Azure Sql,则可以在Context类中添加相关的连接字符串名称:

    If you use Code First for Azure Sql, you could add related connection string name in Context class:

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

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

    3.You could click Tools>Connect to Database>Microsoft SQL Server>enter your server name, username and password about Azure Sql. Then click Test Connection button to check whether you could connect successfully.

    此外,您可以参考此

    Besides, you could refer this article to learn how to access Azure Sql in your project locally.

    这篇关于Azure错误-连接字符串困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆