Tuesday, May 21, 2019

How do I connect to SQL Server 2012 through ASP.NET Core 2.0

Define your connection in the configuration file or context
 e.g
var connection = @"Server=.;Database=Testing;Trusted_Connection=True;ConnectRetryCount=0";

Go to your startup file and add the correct context
 e.g
services.AddDbContext<ExampleContext>(options => options.UseSqlServer(connection)); }
or
var connection = Configuration.GetConnectionString("DatabaseConnection");
            services.AddDbContext<DatabaseContext>(options => options.UseSqlServer(connection));

No comments:

Post a Comment