.net - How to control server name in EF CF? -


i created dbcontext initializer:

public class dropcreateinitializer(of t dbcontext)     inherits dropcreatedatabaseifmodelchanges(of t)     protected overrides sub seed(context t)         context.database.executesqlcommand("create index ix_explan on dbo.explans (progname, bind_time, accessname)")     end sub end class 

what dont understand how control sql server new context create database on. gets created on localhost/sqlexpress.

the dbcontext class optionally takes connection string constructor parameter, means can programatically build connection string using system.data.sqlclient.sqlconnectionstringbuilder class.

here example, in c# (i know sample in vb.net, translation should simple enough, , should illustrate 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;     } } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -