Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7637533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:57:53+00:00 2026-05-31T07:57:53+00:00

I created a DBContext Initializer: Public Class DropCreateInitializer(Of T As DbContext) Inherits DropCreateDatabaseIfModelChanges(Of T)

  • 0

I created a DBContext Initializer:

Public Class DropCreateInitializer(Of T As DbContext)
    Inherits DropCreateDatabaseIfModelChanges(Of T)
    Protected Overrides Sub Seed(context As T)
        context.Database.ExecuteSqlCommand("CREATE INDEX IX_EXPLAN ON DBO.EXPLANS (PROGNAME, BIND_TIME, ACCESSNAME)")
    End Sub
End Class

What I dont understand is how to control the SQL server the new context will create a database on. It gets created on localhost/SQLEXPRESS.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:57:55+00:00Added an answer on May 31, 2026 at 7:57 am

    The DbContext class optionally takes a connection string as a constructor parameter, which means you can programatically build up a connection string using the System.Data.SqlClient.SqlConnectionStringBuilder class.

    Here is an example, in C# (I know your sample is in vb.net, but the translation should be simple enough, and this should illustrate the approach):

    public class MyContext : DbContext
    {
        public MyContext(string serverName, string databaseName)
            : base(GetConnectionString(serverName, databaseName))
        {
    
        }
    
        private static string GetConnectionString(string serverName, string databaseName)
        {
            var connectionBuilder = new SqlConnectionStringBuilder
            {
                DataSource = serverName,
                InitialCatalog = databaseName,
                IntegratedSecurity = true
            };
    
            var connectionString = connectionBuilder.ToString();
            return connectionString;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a context class that implements DbContext BeerRecommenderContext and an intializer that
I created a DbContext like so : public class myDB : DbContext { public
I have a project containing POCO entities. A database context has been created for
I have created an interface that my DbContext class implements, this enables me to
I'm trying to test MVC actions, so i created IRepository and MockRepository public class
I have the following class: public class AuthContext : DbContext { public DbSet<Models.Permission> Permissions
I created an assembly (dll) with the following classes: Person.cs [Table(People)] public class Person
I have an ECMContext class that inherits from DbContext. Within ECMContext there is a
Three class: CustomDbContext ReusableContext DbContext Relation: ReusableContext : DbContext CustomDbContext : ReusableContext Code: public
I created a single page (with code behind .vb) and created Public intFileID As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.