0

I would like to know where to name my database inside a connection string, like this one:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Initial Catalog=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

For what I've reading, the name should be placed next to |DataDirectory|, but the fact is that I've deleted the App_Data folder, because I don't want to have a folder with such a name in my project, so the file .mdf won't be create, and I neither want to be.

What I want is that when going to the Server Explorer view inside Visual Studio Express 2013 for Web I could see the database with the name I've selected above, whichever it is.

ADDITIONAL:

  • I would like to know what are the pros/cons of not having an App_Data folder.

Thank you for your help.

tereško
  • 58,060
  • 25
  • 98
  • 150
  • You are asking multiple questions. You should stick to asking a single question at a time. See this information about App Data Folder. [What is the App_Data folder used for in Visual Studio?](http://stackoverflow.com/questions/528858/what-is-the-app-data-folder-used-for-in-visual-studio) – mason Feb 04 '14 at 16:15
  • 1
    Initial Catalog=MyDatabase; here, mydatabase is your database name. – Kuzgun Feb 04 '14 at 16:16
  • Do you want an MDF in your application (in which case you might as well use `App_Data`), or do you want a regular DB in your SQL Server instance (in which case you should just create it)? – SLaks Feb 04 '14 at 16:20
  • @Kuzgun: I've tested it, and now I see what my problem was. The `Server Explorer` shows me the name of the `Connection String` not the database one. @SLaks: I want a regular SQL Server instance, for what I'm using `Code-First` for creating it. Which are the differences between those both? –  Feb 04 '14 at 16:34

1 Answers1

0

There is no pros/cons. Visual Studio creates temporary Database inside App_Data so that you can test it locally. I prefer hosting Database outside of project (it is just my person preference).

Once the application is ready for production. We need to host the database in separate SQL Server. For example,

<add name="ConnectionString" 
   connectionString="Server=tcp:database.windows.net,1433;Database=MyDatabase;User ID=TheUsername;Password=ThePassword;Trusted_Connection=False;Encrypt=True;" />

Here are SQL Server connection strings.

Win
  • 61,100
  • 13
  • 102
  • 181
  • What if I want to rename the `App_Data` folder, is that possible? –  Feb 04 '14 at 16:27
  • 1
    Yes, it's possible. But you'll manually have to set the permissions as App_Data is one of the only places configured for write access by the server process. Are you renaming it simply because you don't like the name? If so, that's not a good reason for breaking from standard conventions. – mason Feb 04 '14 at 16:33
  • Have no much to say, just that I don't like that name conventions for folders. I think just deleting it, and working with the `Server Explorer` will be fine for now. –  Feb 04 '14 at 16:36
  • @Federico You do not want to rename **App_Data** as msm8bball stated. **App_Data** is standard name, and it services the other purpose too besides database. If you do not like database located inside **App_Data**, you can host it in **SQL Server**. – Win Feb 04 '14 at 16:36
  • That is what I did, but I even don't want `App_Data` and `App_Start` in my project. The applications seems to keep working fine without them, so they can't be **that** important. –  Feb 04 '14 at 16:39
  • @Federico App_Data is not required, but still need App_Start for new ASP.Net Projects. – Win Feb 04 '14 at 16:45
  • I've deleted and all things runs just fine, it is needed for what? –  Feb 04 '14 at 16:49