I checked this website and I didn’t find any solution.
I was made a website with mvc4. I wrote custom data entity.
However, that application works good on localhost but, I cannot use it on a remote server.
here my configurations
web.config connection string
<add name="DefaultConnection" connectionString="Data Source=ipaddress;Initial Catalog=DataContext;User ID=user;Password=pass" providerName="System.Data.SqlClient" />
Here is my DataContext.
That creates new db in local sql server. How I can use remote server with this settings?
public class DataContext : DbContext
{
public DbSet<Sayfalar> sayfa { get; set; }
public DbSet<Uyeler> uye { get; set; }
public DbSet<Roller> rol { get; set; }
public DbSet<Loglar> log { get; set; }
public DbSet<Resimler> resim { get; set; }
}
class dbYenile : DropCreateDatabaseIfModelChanges<DataContext>
{
protected override void Seed(DataContext context)
{
MembershipCreateStatus Durum = new MembershipCreateStatus();
Membership.CreateUser("demo", "123456", "demo@demo.com", "soru", "cevap", true, out Durum);
Durum = new MembershipCreateStatus();
Membership.CreateUser("demo1", "123456", "demo1@demo.com", "soru", "cevap", true, out Durum);
Roles.CreateRole("Yonetici");
Roles.AddUsersToRoles(new string[] { "demo" }, new string[] { "Yonetici" });
//Console.WriteLine(Hatalar.uyelikHatalari(Durum));
}
}
And here Global.asax.cs’s application_start void.
Database.SetInitializer<DataContext>(new dbYenile());
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BundleTable.Bundles.RegisterTemplateBundles();
EF uses a database connection by default that is named the same as the class derived from DbContext, which means your connection above should be named “DataContext”, not “DefaultConnection”. if you want to retain the connection name you can add this to your DataContext class:
otherwise rename your connection string in the web.config to “DataContext”