Sql Server database project template missing in Visual Studio

Possibly save 1 hour of your time: There is a good way to manage your database objects. You can create a solution project for your database as follows.

In Visual Studio, go to File >> New >> Project. You should see the template under Installed >> Templates >> Other Languages >> SQL Server >> SQL Server Database Project.

database project

If you cannot see the above template in Visual Studio 2015, then you need to get SSDT as follows.

Open Visual Studio (mine is 2015) >> choose Tools >> Extensions. Update Updates >> Product updates >> you may find the Microsoft SQL Server Data Tools (SSDT) update that contains the database project template. Select it and Update.

tools and extensions.png

You can see it is installing Microsoft SQL Server Data Tools v14.0.61707.300.

data tools.png

Alternatively, you can also download the tools from

https://msdn.microsoft.com/en-us/mt186501

Book: Microsoft SQL Server 2016: A Beginner’s Guide, Sixth Edition

Advertisements

Consume asmx API web service c#

Possibly save 4 hours of your time: There are projects where you will be consuming external data source through an API they provide. The API could be .asmx web service.

  1. Right click the project in Solution Explorer and choose Add Service Reference.

Add Service Reference.png

2. Click on Advanced at the bottom.

3. Then click on Web Reference to generate access code.

4. Next enter the URL to the external web service. Then click on the arrow icon to find the web service. Then click Add Reference.

add web service

5. Note that the Web References folder is created with the web service code.

6. Here is an example of code calling the web service:

</pre>
ExportTool.Web.org.un.data.NSIStdV20Service service = new ExportTool.Web.org.un.data.NSIStdV20Service();

var xmlData = service.GetCompactData(xmlNode);

Assert.That(xmlData, Is.Not.Null);
<pre>

Book .NET Web Services: Architecture and Implementation

Cannot write XML declaration. WriteStartDocument method has already written it.

Possibly save 1 hour of your time: I was calling an api service that returns xml. I have to pass in a xmlNode element. For some reason, I get the error:

Cannot write XML declaration. WriteStartDocument method has already written it.

Solution: pass in DocumentElement instead of FirstChild

var doc = new XmlDocument();

doc.LoadXml(queryMsg);
var xmlNode = doc.DocumentElement; // instead of doc.FirstChild

ExportTool.Web.org.un.data.NSIStdV20Service service = new ExportTool.Web.org.un.data.NSIStdV20Service();

var xmlData = service.GetCompactData(xmlNode);

Book XML in a Nutshell, Third Edition

Resharper nunit unit test – Could not find a part of the path

Possibly save 1 hour of your time: There are times when your unit test depends on input file. To access the file when using nunit 3.8.1, you can use TestContext.CurrentContext.TestDirectory.

[Test]
public void LoadFileInUnitTestProject()
{
var doc = new XmlDocument();

doc.Load(TestContext.CurrentContext.TestDirectory + "\\Services\\CountryProfile\\population.query.xml");

Assert.That(doc, Is.Not.Null);

}

Book ReSharper Essentials