尝试与在我的电脑上运行的 SQL Server 2012 (localdb) 建立 MVC 连接时出错



我已经像这样设置了我的web.config:

<add name="DefaultConnection" connectionString="Data Source='C:UsersMarilouAppDataLocalMicrosoftMicrosoft SQL Server Local DBInstancesv11.0authentication.mdf';Initial Catalog=javacert;Persist Security Info=True;User ID=sa;Password=yyy" providerName="System.Data.SqlClient" />

但我得到的消息是:

   Message=The provider did not return a ProviderManifestToken string.
   Source=EntityFramework
   StackTrace:
        at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
        at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
   InnerException: System.Data.SqlClient.SqlException
        HResult=-2146232060
        Message=A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
        Source=.Net SqlClient Data Provider
        ErrorCode=-2146232060

似乎您正在使用 LocalDB。从此 MSDN 文章 (http://blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx) 中,连接字符串如下所示:

Data Source=(localdb)v11.0;Integrated Security=true;AttachDbFileName=C:MyDataDatabase1.mdf".