The Upgrade Toolkit objects that shipped with Microsoft Dynamics NAV 2013 have a good example of code that works directly with SQL Server through the .NET Framework library. On the product media, navigate to this location:
Posted inDynamics NAV & BC Tips & tricks