As I have been following a MusicStore tutorial, new MVC3 project created a following connection string for me:
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
My model tables got created in .\SQLEXPRESS and all the users/roles tables are stored in the aspnetdb.mdf in the App_Data folder.
I would like to have the model tables and user/roles tables on my .\SQLSERVER or localhost rather then scattered between .\SQLEXPRESS and the mdf file. I’m struggling with the right connection string. Can anyone suggest the right one please?
Everyone who does this has to make sure that name of the connection string should be the name of the context class derived from the *DbContext*
It sounds like you need to run aspnet_regsql on your ApplicationServices database. You can find it in C:\Windows\Microsoft.Net\Framework\4.xxx\aspnet_regsql.exe.
A default project uses ApplicationServices db as default for membership, roles, and profile. The sproc dbo.aspnet_CheckSchemaVersion is a sproc in the ASP.NET SQL Membership Provider schema.
Response to comment #1
Do you have a database instance running on your machine named SQLSERVER? The exception you mentioned is a common one, if asp.net cannot find the database using your connection string.
Response to comment #2
That makes sense. Integrated Security=true tells the connection to use the process running the MVC app (usually IIS app pool) for the sql server login. If you are testing from Visual Studio / Web Developer Express / etc, the web server is likely running on a process with your windows account. So if you can windows auth against the db server, MVC should also be able to.
User Instances are meant for SQLEXPRESS.