Avatar of brotherbill999
brotherbill999
 asked on

EF 4.1 Code First Configure Database

How do I configure an EF 4.1 Code First Database, built on the fly, so that its name is 'MyDatabase', for example.
I don't like the default database name.
ASP.NET

Avatar of undefined
Last Comment
brotherbill999

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
disrupt

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
brotherbill999

ASKER
In http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx, comments area:

wjn161
7 Apr 2011 1:10 AM

@ Martin Erskine

the DbContext has some override versions ,you can pass a connectionString like that

public CategoryContext(): base(connectionString){}

>>> This provides the answer.
brotherbill999

ASKER
Thank you.  It is just one line of code, but it is a CRITICAL line of code! ;-)
brotherbill999

ASKER
Some tips on creating the web.config entry.

0. Database already exists
1. Add WebForm page: WebForm1.aspx
2. Drag SqlDataSource to Design surface
     a. Using smart tag, Configure Data Source...
     b. Choose Your Data Connection wizard step
            Which data connection? Click: New Connection...
              Add Connection dialog
             Server name: MY-PC\SqlExpress
        Connect to a database
                  (o) Select or enter a database name: MyDataBaseName
              Click: Test Connection
        Click: OK
      c. Grab Connection String:
         Data Source=MY-PC\SqlExpress;Initial Catalog=MyDataBaseName;Integrated Security=True
      d. Click Next
      e. [x] Yes, save this connection as MyDataBaseNameConnectionString
      f. Click: Next until Click Finish

If you have used C:\Windows\Microsoft.NET\Framework\v2.0.50727> aspnet_regsql.exe to create the database, change connection string "ApplicationServices" to point to the same config as MyDataBaseName.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23