如何使用MVC3 EF4远程连接到SQL Server 2008

时间:2011-03-15 06:39:16

标签: asp.net sql-server asp.net-mvc-3 entity-framework-4

我正在尝试远程连接,我首先使用EF4 ctp5代码在我的MVC3上使用以下连接字符串

<add name="ApplicationServicesX"
     connectionString="provider=System.Data.SqlClient;provider connection string='Data Source=asc-svr2;
     Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60;
     multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />

并且它给出了错误

[ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.]

Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

我的控制器看起来像这样

 public ActionResult Index()
 {
     var post = cmsDB.Posts.ToList();
             return View(post);
}

当我在本地计算机上运行代码时,没有任何问题,但是当我进入时 远程连接到SQL Server 2008会出现问题。

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您的连接字符串配置为使用集成Windows身份验证(Integrated Security=True)。为此,请确保已在IIS中启用NTLM。此外,如果SQL Server所在的物理机器与Web服务器不同,则可能需要configure delegation。作为替代方案,您可以将SQL身份验证与固定帐户一起使用:

<add name="ApplicationServicesX"
     connectionString="provider=System.Data.SqlClient;provider connection string='Data Source=asc-svr2; Initial Catalog=AdventureWorks;User Id=foo;Password=secret;Connection Timeout=60;multipleactiveresultsets=true'" 
     providerName="System.Data.EntityClient" />