.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
Post a Comment