连接字符串'服务器'不支持关键字

时间:2018-01-31 14:50:23

标签: asp.net-mvc ado.net web-config azure-web-sites connection-string

我将ASP.NET MVC 5网站部署到MS Azure平台。但是,当我的Web应用程序尝试连接到数据库时,应用程序会抛出异常:

  

'服务器'不支持关键字

我从Azure门户网站获取了连接字符串(ado.net)。

<connectionStrings>
    <add name="NiqaatyEntities" 
         connectionString="Server=tcp:ServerName.database.windows.net,1433;Initial Catalog=DatabaseName;Persist Security Info=False;User ID=Login;Password=Password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" 
         providerName="System.Data.EntityClient"/>
</connectionStrings>

我改变了:

  • 服务器名
  • 数据库名
  • 登录
  • 密码

我使用EDMX的数据库优先方法。

有没有解决方案?

1 个答案:

答案 0 :(得分:1)

您说您使用EDMX的数据库优先方法,因此您需要使用特殊类型的连接字符串,如下所示:

  

元数据= RES:// /Model1.csdl|res:// /Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider   连接字符串=&#34;数据源=(本地);初始   目录=测试;集成   安全= TRUE; multipleactiveresultsets = TRUE;应用=的EntityFramework&#34;

在此连接字符串中,您将拥有Dim ctx As DirectoryServices.AccountManagement.PrincipalContext = New DirectoryServices.AccountManagement.PrincipalContext(DirectoryServices.AccountManagement.ContextType.Domain, "MyCompany.co.uk") Dim usr As DirectoryServices.AccountManagement.UserPrincipal = DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(ctx, "User ID") Dim grp As DirectoryServices.AccountManagement.GroupPrincipal = New DirectoryServices.AccountManagement.GroupPrincipal(ctx) grp.Name = "Google-*" grp.Members.Contains(usr) Dim srch As DirectoryServices.AccountManagement.PrincipalSearcher = New DirectoryServices.AccountManagement.PrincipalSearcher(grp) For Each s As DirectoryServices.AccountManagement.GroupPrincipal In srch.FindAll() s.Members.Remove(ctx, DirectoryServices.AccountManagement.IdentityType.SamAccountName, "User ID") s.Save() Next 属性,这是您的连接字符串:

  

服务器= TCP:ServerName.database.windows.net,1433;初始   Catalog = DatabaseName; Persist Security Info = False; User   ID =登录;密码=密码; MultipleActiveResultSets = FALSE;加密= TRUE; TrustServerCertificate = FALSE;连接   超时= 30;