Step 3 : Specifying Database Connection Information

In this step you will set up a database key in the ABusinessObject class that is used as a lookup key into the application configuration file to determine how to connect to your application's database at runtime and at design-time by the MM .NET Business Layer Generator. This step configures your application to access the SQL Server Northwind database.


Note: If you do not have the Northwind database in SQL Server, check out the MM .NET Help topic How can I create the Northwind DBC for SQL Server Express or SQL Server?

  1. Go to the Solution Explorer and click the ABusinessObject.vb file to open it.

  2. In the constructor of the ABusinessObject class, notice the DatabaseKey value is set to "EntityDataModelContainer":

    ''' <summary>
    ''' Constructor
    ''' </summary>
    Public Sub New()
     
    	' Enter the default database key as specified in the app.config file
    	Me.DatabaseKey = "EntityDataModelContainer"
    	Me.RetrieveAutoIncrementPK = True
     
    	' Specify the default command type for data retrieval
    	Me.DefaultCommandType = CommandType.StoredProcedure
     
    End Sub

    This value is used as a key to look up database information in your application's app.config or web.config file. You will add this database information to the configuration file in a later step.

  3. Notice the line of code in the previous step that sets the RetrieveAutoIncrementPK property to true.

    This setting tells the data access layer to automatically retrieve new database-generated primary key values (such as SQL Server Identity columns) after inserting a new record in the database. This doesn't happen by default in the Entity Framework, so MM .NET does the extra work for you.

    Notice the code in the constructor that sets the DefaultCommandType property to CommandType.StoredProcedure:

    ' Specify the default command type for data retrieval
    Me.DefaultCommandType = CommandType.StoredProcedure
    

    We consider the use of stored procedures a best practice, so we are specifying that, by default, the business objects use stored procedures to access data. That said, when you use LINQ to retrieve entities, as you will do in this Jump Start, this setting is ignored. However, if you decide to try your hand at retrieving entities using stored procedures, you're good to go!


    Note: You may be wondering why we are setting properties that seem to be database specific on the business object. This is simply a convenience feature. At run time these values are not used directly by the business object, but passed along to the associated data access object.

  4. In the Solution Explorer, click the app.config file to open it in the code-editing window. This configuration file contains settings that tell the application (among other things) about each database used by the application. You should see the following elements that specify the connection string for attaching to the Northwind database:

      <databases>
        <add key="Northwind\Connection" value="Data Source=(local);Initial Catalog=Northwind;Integrated Security=True" />
        <add key="Northwind\DataAccessClass" value="DataAccessSql" />
        <add key="EntityDataModelContainer\DataAccessClass" value="DataAccessSqlEF" />
      </databases>

    The first "Northwind\Connection" entry is only used at design time by the MM .NET Business Layer Generator to retrieve business rules and defaults from the database.

  5. If you want to use SQL Server authentication, can specify a user id and password on your development machine so the MM .NET builders can access your database. For example:

      <databases>
        <add key="Northwind\Connection" value="server=(local);uid=sa;pwd=;database=NorthWind;"/>
        <add key="Northwind\DataAccessClass" value="DataAccessSql"/>
        <add key="EntityDataModelContainer\DataAccessClass" value="DataAccessSqlEF"/>
      </databases>


    Note:If you are using SQL Server authentication on your end-user's computers, the user id and password should not be stored in the app.config file. Instead, it is retrieved at run time from the user login.

  6. The EntityDataModelContainer\DataAccessClass entry is used at runtime to load the appropriate MM .NET data access class for the Entity Framework. The Entity Framework adds its own connection string information to the app.config file as you will see later in this Jump Start.

    If you are having problems connecting to your database, see the MM .NET Help Topic If You Are Having Problems Connecting...

    For more information on connection strings see the Help topic How Database Connections Work in MM .NET.

  7. Save changes to the app.config file by pressing Ctrl+S, then close the app.config file in the editor.


See Also:
Step 4 : Creating Business Classes w/ the Business Generator


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/19/18
Comment or report problem with topic