Author: Md Rijwan Ansari

Create SQL Server Database Project With Visual Studio. Create or compare two Databases.

Posted on Updated on

Here, we are going to learn about SQL Server Database Project (Template) available in Visual Studio. I will cover following points:

  • Introduction of SQL Server Database Project.
  • Create New SQL Server Database Project.
  • Import database schema from an existing database, a .sql script file or a Data-tier application (.dacpac) the Project.
  • Publish to create new Database in SQL server.
  • Compare Two Database and find differences.
  • Compare, Update or Create update Scripts.

Database plays a most important role in any application and it becomes difficult to manage the project when number of tables, views, stored procedures increases.

Consider scenarios where multiple developers are working on a project for next release, some are working on Bugs or adding new features which again require some or many changes in database. Most of the cases developers take note of DB (Database) changes manually. Some time they miss some changes which cost in production. There are many cases that Dev, UAT and production DB are different which is again hassle to identify the differences.

There are number of tools available in market for comparing DBs but are costly or paid solution.

So, in this article we will discuss and learn about SQL Server Database Project with is available in Visual Studio which is free. Yes Free!!

Prerequisites: Visual Studio (2015 or 2017) and MS SQL  Server. I am using VS2017 and SQL Server 2017 Developer for illustration.

Introduction:

You can create a new database project and import database schema from an existing database, a .sql script file or a Data-tier application (.dacpac). You can then invoke the same visual designer tools (Transact-SQL Editor, Table Designer) available for connected database development to make changes to the offline database project, and publish the changes back to the production database. The changes can also be saved as a script to be published later. Using the Project Properties pane, you can change the target platform to different versions of SQL Server (including SQL Azure). (copied MS Docs)

Create New SQL Server Database Project

  1. Open Visual Studio and create a blank solution.

2. Add a Project.

3. Select SQL Server from Left panel and SQL Server Database Project. Name the project ( here SampleAccount.)

Import database schema from an existing database, a .sql script file or a Data-tier application (.dacpac) the Project

4. Right click on project and select import. There will be three options: Data-Tier Application (.dacpac), Database, Scripts. Select Database.

5. Provide Connection string. i.e. Select/Insert Server, authentication type, Database.

6. Set the import settings as highlighted.

7. Click Start which will show the progress window as:

After Finish we will see the tables, views and stored procedures in our project.

This is how we can add the database in the SQL Server Database Project.

Publish to create new Database in SQL server.

The database above in the project can be used to create new database with same schema.

  1. Right click on the project and choose the publish option.

2. Provide Connection: Server name, Authentication Type , credentials. If we want to publish as new database then choose default database, or choose specific database to publish.

3. We can generate script or publish directly. You can explore advance options as well to apply rules on publish.

Now our new database is created or generated script can used to create.

Compare Two Database and find differences.

This section we will how to compare two database to identify the differences like Dev, UAT or UAT, Prod likewise.

  1. Right click in the SQL Database project and choose schema compare.

2. Select Source and Target database. Prove connection. Note: we can compare two databases or another database with the project database.


3. Click Compare

The we will the differences between source and target database.

There will be deleted, edited and added objects as shown.

Compare, Update or Create update Scripts.

Another we can update the target database or generate update script to push source version.

  1. Complete the compare part. then there is option to do the job.

Update option directly update to target database and generate script will give sql script.

From above consideration, we don’t need to create migration script or plan for DB. We can easily compare the relevant database tables, views and stored procedures in no time.

So, any changes can be incorporated and make database managing in effective and efficient way.

Advertisements

Using Web App for Containers in a Multi-Tier Application

Posted on

Ahmed Elnably joins Scott Hanselman to discuss a sample project, Developer Finder, that was created to showcase how to use Web App for Containers in the context of a multi-tiered application.

https://channel9.msdn.com/Shows/Azure-Friday/Using-Web-App-for-Containers-in-a-Multi-Tier-Application/player

Build Your Own Cortana Skill

Posted on Updated on

Building a Cortana skill means that Cortana can use your bots, services, websites, and apps to help people – but did you know that you can write the whole skill with C# and .NET? During this session, we’ll learn about Cortana and the Skills Kit, build a skill step-by-step, and discuss how you can work with Cortana to build personalized, intelligent experiences for your users. Skills built in this session will work across Windows 10, Android, iOS, and headless devices such as the Harman Kardon speaker. Following this talk, you’ll understand how Cortana skills work, be able to build your own skill, and know where to go for help and support along the way.

https://channel9.msdn.com/Events/dotnetConf/2017/T119/player

What’s New in Visual Studio 2017

Posted on Updated on

Visual Studio is a productivity game changer for C#! The .NET Compiler Platform (“Roslyn”) enables many new experiences that will change the way you write and debug code. In this session, we’ll dig into features that bring a new level of awesome to the C# language and IDE experience. Come learn about new language features, refactoring support, major debugging enhancements, code-aware frameworks, and much more!

https://channel9.msdn.com/Events/dotnetConf/2017/T118/player

 

What’s New in Entity Framework Core 2.0

Posted on Updated on

Entity Framework Core is a lightweight, extensible, and cross-platform version of the popular Entity Framework data access technology. In this session we’ll look at what’s new in EF Core 2.0 and what the team has planned for upcoming releases.

Video:

https://channel9.msdn.com/Events/dotnetConf/2017/T221/player

 

How to set and get the session value in asp.net core.

Posted on Updated on

The Microsoft.AspNetCore.Session package provides middleware for managing session state.

  1. Add the following heightened line in your Startup.cs

public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// Adds a default in-memory implementation of IDistributedCache
 services.AddDistributedMemoryCache();
services.AddSession(options =>
{
// Set a time for session
options.IdleTimeout = TimeSpan.FromSeconds(200);
options.Cookie.HttpOnly = true;
});
}

public void Configure(IApplicationBuilder app)
{
app.UseSession();
app.UseMvcWithDefaultRoute();
}
  1. Following line of code is needed to set the session value.

public class HomeController : Controller
{
const string SessionStoreName = "_StoreName";
const string SessionStoreID = "_StoreID";

public IActionResult Index()
{
// Requires using Microsoft.AspNetCore.Http
 HttpContext.Session.SetInt32(SessionStoreID, 3);
 HttpContext.Session.SetString(SessionStoreName, "ABC Store");
return RedirectToAction("SessionStore");
}
  1. To get the session value

public IActionResult SessionStore ()
{
var storename = HttpContext.Session.GetString(SessionStoreName);
var storeID = HttpContext.Session.GetInt32(SessionStoreID);
return Content($"Store Name: \"{ storename }\",Store ID: \"{ storeID}\"");
}

Rijwan Ansari

The Microsoft.AspNetCore.Session package provides middleware for managing session state.

  1. Add the following heightened line in your Startup.cs
  1. Following line of code is needed to set the session value.
  1. To get the session value

View original post

How to Restore the deleted/quarantined items by Windows Defender?

Posted on

Rijwan Ansari

Sometimes Windows Defender can detect your custom app, .exe file or other files as a threat and might have been deleted by the defender. If you want to restore it back here are some steps to follow.

Steps:

  1. Open the Windows Defender, you can directly open by typing Windows Defender Security Center in the search.

2. After opening, Click on Virus and Threat Protection.1.

3. Look on Scan History, there you can see the Quarantined threats.

2

4. Go to that Quarantined threats, select the quarantined items, to restore click restore option and for removal click on remove option.

5. To see the full history of Quarantined items, click on See Full History

In this way, you can restore or remove your quarantined items from windows defender security center.

For the proactive defense or to exclude your apps, files, and folders not to scanned by Windows Defender, there is an Exclusions option…

View original post 167 more words