How To Create A Database In SQL Server Using Console Application In Visual Studio 2017RC

First, create a console application in Visual Studio 2017.

visual studio

Click on the Project and a window will appear, as shown below.

visual studio

Select Console App (Framework) and give the proper name. You will see the following screen.

visual studio

Let's start writing lines of code to achieve our task.

visual studio

Write a few lines of code to create a SQL connection. The below command is used to to open the SQL connection.

visual studio

The SQL command should be created inside a using statement. It receives SQL statement as first argument.

The SQL command initializes a new instance of the SqlCommand class.

ConnSource.Open() //Open the Connection

Cmds.ExecuteNonQuery // executes SQL statement against the connection and returns the number of rows affected.

visual studio

Here, I am creating a new table named Projects in my destination dbASPNETCoreDemoDB.

My Source DB is EPM –dbo.msp.
 
EpmProject_UserView is my view.

Hey, don’t forget to set up your target connection in your app settings, as shown below.

visual studio


Similar Articles