VS2013 An exception occurred while initializing the database

I’m doing a code first Entity database

{“An exception occurred while initializing the database. See the InnerException for details.”}

It was working fine, but I decided to delete the physical database to see it recreate it, but it just fails every time.

I get the error

Cannot attach the file ‘C:\ASP\OdeToFood\OdeToFood\App_Data\OdeToFoodDb.mdf’ as database ‘OdeToFoodDb’.”}

Its code first so I don’t understand why its not recreating the database.

 

 

So deleting the file from Visual Studio was a dumb idea.

SQL still has it registered.

Fire up MS Sql Management Tool, connect to the server in my case

(localdb)\v11.0

You will see the database, still exists, delete it, you will get an error. The file doesn’t exist. Refresh and its gone from SQL. Now run your code again and all is good.

So delete the DB from the management tool not visual studio

Advertisements

Perform Specific Button click event when user press Enter key in Textbox

Put your form inside an asp.net panel control and set its DefaultButton attribute with your button ID. See the code below:

 

<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
         <ContentTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Send" />
             </ContentTemplate>
          </asp:UpdatePanel>
</asp:Panel>

VS 2013 : Project name with number in brackets

In file C:\Users\Username\Documents\IISExpress\config\applicationhost.config, under section

<sites>

</sites>

there was all websites (projects) I have ever opened. I deleted these items and now, on New Website there is no number in brackets. NOTE: I think it is not wise to delete the entire file but only the part that applies to sites/projects.

 

 

Reff: http://forums.asp.net/t/1953275.aspx?Project+name+with+number+in+brackets

Visual Studio 2013 Change the Default Location for Projects

For corporate office user my document is always redirected to a file server where creating exe file is restricted.

1. Create a folder in c drive called: vs 2013

2. Inside that folder create 2 folders

Projects

Templates

3. Inside Templates, create another 2 folders:

ItemTemplates

ProjectTemplates

4. Open visual studio and follow the steps

  • On the Tools menu, select Options.
  • From the Projects and Solutions folder, select General.
  • In the Visual Studio projects location text box, enter a location for files and projects.

 

vs2013

 

And you should be all set.