-
-
Save polatengin/464d78a39de20e32bd4c33f62b847bbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Asp.Net Core uygulamalarında Environment (Ortam) bilgisine göre Database ConnectionString (Veritabanı Bağlantı Cümlesi) belirlemek |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppDataContext : DbContext | |
{ | |
public DbSet<Customer> Customers { get; set; } | |
public DbSet<Product> Products { get; set; } | |
public DbSet<Employee> Employees { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"ConnectionStrings": { | |
"AppConnectionString": "Data Source={SQLSERVERIP};Initial Catalog={DBNAME-PREFIX};User Id={USERNAME};Password={PASSWORD};" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddDbContextPool<AppDataContext>(options => | |
{ | |
var builder = new SqlConnectionStringBuilder(Configuration.GetConnectionString("AppConnectionString")); | |
builder.InitialCatalog += "_" + HostingEnvironment.EnvironmentName; | |
if (HostingEnvironment.IsDevelopment()) | |
{ | |
builder.InitialCatalog += "_" + Environment.MachineName; | |
} | |
var connectionString = builder.ConnectionString; | |
options.UseSqlServer(connectionString); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment