1

Hy!

I'm new to ASP.NET MVC 5. I try to change the default database name. But I don't know how. My goal is to have only one database for the whole application.

My actual working Web.Config:

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

This Web.Config file should look like this and should work ^^ (actual I get a error that the database could not be created and the physical name may be incorrect)

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

Thanks for help :)

1 Answer 1

4

You need to add |DataDirectory|\ before Example.mdf, like below:

 <connectionStrings>
    <add name="DefaultConnection" 
    connectionString="DataSource=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Example.mdf;Initial Catalog=Example;Integrated Security=True"
     providerName="System.Data.SqlClient" />
</connectionStrings>
Sign up to request clarification or add additional context in comments.

Comments

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.