- Start Visual Studio. Select New Project. Choose Templates | Visual C# | Windows | Web. Choose ASP.NET Web Application.
The New Project dialog box appears.
- Type in a new Name, Solution Name and/or Browse to a new Location. Click OK
The project is created.
- In the Solution Explorer pane on the right, double click on the file Web.config.
The editor shows the contents of Web.config.
- Add in a new section for connectionString, as shown in the screenshot below.
Note: obviously, the connection string values will vary depending on the server name, database, and user name, so they need to be changed accordingly.
- In the Solution Explorer pane, right click on the Controllers folder node and choose Add Controller.
The Add Scaffold dialog box appears.
- Select an appropriate controller e.g. Web API 2 Controller with read/write action. Click Add. Type in the new Controller name, e.g. LogController. Click Add.
A skeleton controller is created.
- Open the newly created file e.g. LogController.cs in the editor. Type in a method e.g. Get. An example is shown below.
Monday, April 11, 2016
Create a simple C# Web Service API to insert a record into a SQL Server database
Creating a Web Service API in C# that talks to a SQL Server database in Visual Studio is relatively straightforward. It comes with a number of wizards that guide through the process. First, create a project by