Jus*_*ick 26 c# sql-server asp.net-mvc entity-framework azure-sql-database
当我尝试连接到SQL Azure时,我收到以下错误消息.
此版本的SQL Server不支持Windows登录
我正在使用Azure连接字符串.在开发时我正在运行SQL Server Express.当我尝试从数据库中获取某些数据时,会抛出此特定错误.
我正在使用的上下文在using子句中运行,请参阅下文
function List<SomeType> GetList(string dbContextName)
{
using (MyDbContext context = new MyDbContext)
{
return context.SomeTypes.ToList();
}
}
Run Code Online (Sandbox Code Playgroud)
我们使用的是Entity Framework 4.2版,ASP.NET MVC 3和.NET 4.0.
我该如何解决这个问题?
Jos*_*980 36
我使用user/pass仍然收到错误消息.但是,我将此添加到我的连接字符串中并且它有效.
Trusted_Connection=False;Encrypt=True;
Run Code Online (Sandbox Code Playgroud)
其他人已经提到过Az,SQL Azure只支持SQL Server身份验证.您可以阅读有关SQL Azure的指南和限制的更多信息.以及SQL Azure的安全准则和限制.
您必须在MASTER数据库中自己创建LOGIN,然后您需要在自定义Azure数据库中创建USER.另外,不要忘记执行sys.sp_addrolemember以向您的用户授予一些权限.
更多关于管理用户和登录名在SQL Azure中可以发现在这里.
最后,您可以随时查看连接字符串的宝贵来源.
小智 6
您可能使用了错误的连接字符串,这是适用于我的情况的连接字符串格式:
"ConnectionString":"Server = tcp:xxxx.database.windows.net,1433; Database = xxx; User ID = xxx; Password = xxx; Encrypt = True; TrustServerCertificate = False; Connection Timeout = 30;"
1.**Windows Authentication** is not supported in Azure so you should go with **SQL Server Authentication**.
2.When you use SQL server Authentication you should pass User Id(Login in SQL server) and Password(Password in SQL server).
3.User Id should contain space in between should not be like UserId.
4.Trusted_Connection should be false.
The connection string in *appsettings.json* look like this:
"ConnectionStrings": {
"DBContext": "Server=ServerName;Database=DbName;User Id=loginName;Password=loginPassword;Trusted_Connection=false;MultipleActiveResultSets=true"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27293 次 |
| 最近记录: |