问题
I'm working my way through the MVC Music Store Tutorial and am running into an issue when I try to connect to the database using the entity framework model. I've tried a number of these walkthroughs, and I'm continuing to run into problems when I get to this part.
I do not want to use SQL Compact Edition (although I've tried to install it just to get the tutorials to work). Rather, I have SQL Server Developer 2005 Edition as well as a named instance of SQL2008 Express (again, installed just to see if I could get the tutorial to work). Here is my connection string:
<connectionStrings>
<add name="MusicStoreEntities"
connectionString="server=2-BQZ5DP1\DELS2008EXPRESS;Integrated Security=SSPI;database=MvcMusicStore"/>
</connectionStrings>
The closing tag for the connectionStrings element will not post in the code snippet, so pretend that it is there.
What do I need to do differently? 2-BQZ5DP1 is the name of my box, and the SQL Express instance is a named instance.
回答1:
You generally need MultipleActiveResultSets=True with Entity Framework when you're using SQL Server editions other than Compact. Depending on what the error you are seeing is, that might be your problem. For more on connection string options, see this blog:
http://blogs.msdn.com/b/aspnetue/archive/2012/08/14/sql-server-connection-strings-for-asp-net-web-applications.aspx
回答2:
how about
ConnectionString="Data Source=.\DELS2008EXPRESS; Initial Catalog=MvcMusicStore; Integrated Security=SSPI;"
回答3:
You could be missing the username and password from your conn string? Application and timeout are other parameters you might need depending on your set up. Check out http://www.connectionstrings.com for more help with SQL 2005.
Furthermore, Entity Framework requires many more parameters in the connection string. I have not used the code first approach yet but if you have existing tables you wish to map then EF has a wizard you can use to identify the database objects you want to work with. To get this far you have to provide a valid connection string to the dialog. In doing so VS will populate your web.config with the well formed and fully constructed conn string for use with EF.
来源:https://stackoverflow.com/questions/12167363/mvc3-music-store-tutorial-connection-string-issue