3

I just started using C# and MVC3, and I've been following the MVCMusicStore tutorial at ASP.NET website.. In the tutorial it used

<add name="MusicStoreEntities"
 connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"
 providerName="System.Data.SqlServerCe.4.0"/>

as the connection string... In my application I changed it to

<add name="FashionStyle.StoreEntities"
     connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|FashionStyle.StoreEntities.mdf;Integrated Security=True;User Instance=True" 
     providerName="System.Data.SqlClient"/>

But I found out the actual database file is in

C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA

My question is how do I move it from there to the App_Data folder in the project and make it so that Visual Studio 2010 will know where to look for the database file? This is because the application is a group work and I want to share it with my team members.

2 Answers 2

1

actually what they have used is .sdf file ie., Sql Server Compact Database file and what you are using is .mdf file which is a Sql Server Database file.

now if you have created that database either through VS Server Explorer or Sql Server Management Studio then I think you dont have to worry, just use

<add name="FashionStyle.StoreEntities" 
     connectionString="Data Source=.\SQLEXPRESS;
                       Initial Catalog=yourDatabase;
                       Integrated Security=True;
                       User Instance=True";
     providerName="System.Data.SqlClient"/>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, in the new version you're telling Visual Studio to ask SQL Server for the database as long as it knows where the database is there's no problem. It depends now whether you want to stick to using SQL Server Express or switch back to SQL Server Compact. In any case you can use SQL Server Management Studio to back up the database and give your colleagues the backup which they can restore to their own SQL Server Express installs, and your application can access it from there.
0

Visual Studio will only know where to find it if you tell it where to find it. Simply backup the database using standard SQL Server procedures and restore it where is most appropriate then update your appconfig/webconfig + Server Explorer to point to it.

5 Comments

If don't mind, would you care to explain how do I do that? I opened up the server explorer pane and I'm not sure what to do..
Updating the Server Explorer pane is only necessary if you plan to maintain your ERD or update your EF data sources. But it is basically the same way that the tutorial told you to do it when you initially did so. msdn.microsoft.com/en-us/library/z6sa01t4%28v=vs.71%29.aspx - Did you need direction on backup and restoration of your database?
^ Yes please :< I just started using visual studo (C# and MVC too) less than 2 months ago...
All of that information is made available from the MSDN: Backup - msdn.microsoft.com/en-us/library/ms187510.aspx; Restore - msdn.microsoft.com/en-us/library/ms177429.aspx. I believe both of those tutorials assume you are using a full version (not Express or Compact) of SQL Server but I'm sure Google will be your friend in finding detail about the other editions if necessary.
@WilliamEdwinSieh - You would do much better asking on server fault how to do sql server backups and restores.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.