We have an existing ASP.NET Web API which uses a code-first approach with Entity Framework pointing to am on-premise SQL Server. We were managing using DbContext
.
我们有一个现有的ASP.NETWeb API,它使用代码优先的方法,使用实体框架指向本地SQL Server。我们正在使用DbContext进行管理。
We migrated the database from on-premise SQL Server to Azure SQL. Now the requirement is to point existing Web API application to Azure SQL to the same database. It is not working if we directly change the connection string in the web.config
.
我们将数据库从本地SQL Server迁移到Azure SQL。现在的要求是将Azure SQL的现有Web API应用程序指向相同的数据库。如果我们直接更改web.config中的连接字符串,它将不起作用。
Could you please let us know the steps involved?
您能告诉我们所涉及的步骤吗?
Thanks.
谢谢。
更多回答
Can you share your .csproj details
你能分享你的.csproj详细信息吗
优秀答案推荐
Here is the way i acheived Connecting Application to Azure SQL by changing in web.config and DBContext
以下是我通过更改web.config和DBContext将应用程序连接到Azure SQL的方法
1 - Check your connection string with Providername included
1-检查包含Providername的连接字符串
<connectionStrings>
<add name="MyDbConnection" connectionString="Server=tcp:******.database.windows.net,1433;Initial Catalog=entity;Encrypt=True;
TrustServerCertificate=False;Connection Timeout=30;Authentication=Active Directory Default;" providerName="System.Data.SqlClient" />
</connectionStrings>
2 - provide your connection string name in your DBContext
2-在DBContext中提供您的连接字符串名称
public MyDatabaseContext() : base("name=MyDbConnection")
{
}
3 - Run Solution
Result
3次运行解决方案结果
更多回答
Thanks for the response. I was getting "Invalid value for key 'authentication' " error when i use Authentication=Active Directory Default in connection string, Any idea ? But it worked when i used Authentication=Active Directory Integrated in the conn string.
感谢您的回复。当我在连接字符串中使用AUTHENTICATION=Active Directory默认值时,我得到了“密钥‘AUTHENTICATION’的无效值”错误,你知道吗?但当我在conn字符串中使用身份验证=集成的Active Directory时,它就起作用了。
Authentication=Active Directory Integrated specifies that the application should use Windows Integrated Authentication to connect to the database. please refer to this link
身份验证=Active Directory集成指定应用程序应使用Windows集成身份验证来连接到数据库。请参考此链接
我是一名优秀的程序员,十分优秀!