Skip to content

Commit 5735765

Browse files
committed
added all sql server types
1 parent 32cf01d commit 5735765

15 files changed

Lines changed: 247 additions & 3 deletions

File tree

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
[Dd]ebugPublic/
1212
[Rr]elease/
1313
[Rr]eleases/
14-
x64/
15-
x86/
14+
#x64/
15+
#x86/
1616
build/
1717
bld/
1818
[Bb]in/
1919
[Oo]bj/
2020

2121
# SQL Server types
22-
SqlServerTypes/
22+
#SqlServerTypes/
2323

2424
# Roslyn cache directories
2525
*.ide/

src/GeoJSON.Net.Contrib.MsSqlSpatial/GeoJSON.Net.Contrib.MsSqlSpatial.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,28 @@
6767
<Compile Include="Sinks\Helpers\SqlSpatialExtensions.cs" />
6868
<Compile Include="Sinks\SqlGeographyGeoJSONSink.cs" />
6969
<Compile Include="Sinks\SqlGeometryGeoJSONSink.cs" />
70+
<Compile Include="SqlServerTypes\Loader.cs" />
7071
<Compile Include="WktConvert.cs" />
7172
</ItemGroup>
7273
<ItemGroup>
7374
<None Include="app.config" />
7475
<None Include="packages.config" />
7576
</ItemGroup>
77+
<ItemGroup>
78+
<Content Include="SqlServerTypes\readme.htm" />
79+
<Content Include="SqlServerTypes\x64\msvcr120.dll">
80+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
81+
</Content>
82+
<Content Include="SqlServerTypes\x64\SqlServerSpatial140.dll">
83+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
84+
</Content>
85+
<Content Include="SqlServerTypes\x86\msvcr120.dll">
86+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
87+
</Content>
88+
<Content Include="SqlServerTypes\x86\SqlServerSpatial140.dll">
89+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
90+
</Content>
91+
</ItemGroup>
7692
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7793
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
7894
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.IO;
3+
using System.Runtime.InteropServices;
4+
5+
namespace SqlServerTypes
6+
{
7+
/// <summary>
8+
/// Utility methods related to CLR Types for SQL Server
9+
/// </summary>
10+
public class Utilities
11+
{
12+
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
13+
private static extern IntPtr LoadLibrary(string libname);
14+
15+
/// <summary>
16+
/// Loads the required native assemblies for the current architecture (x86 or x64)
17+
/// </summary>
18+
/// <param name="rootApplicationPath">
19+
/// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications
20+
/// and AppDomain.CurrentDomain.BaseDirectory for desktop applications.
21+
/// </param>
22+
public static void LoadNativeAssemblies(string rootApplicationPath)
23+
{
24+
var nativeBinaryPath = IntPtr.Size > 4
25+
? Path.Combine(rootApplicationPath, @"SqlServerTypes\x64\")
26+
: Path.Combine(rootApplicationPath, @"SqlServerTypes\x86\");
27+
28+
LoadNativeAssembly(nativeBinaryPath, "msvcr120.dll");
29+
LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial140.dll");
30+
}
31+
32+
private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName)
33+
{
34+
var path = Path.Combine(nativeBinaryPath, assemblyName);
35+
var ptr = LoadLibrary(path);
36+
if (ptr == IntPtr.Zero)
37+
{
38+
throw new Exception(string.Format(
39+
"Error loading {0} (ErrorCode: {1})",
40+
assemblyName,
41+
Marshal.GetLastWin32Error()));
42+
}
43+
}
44+
}
45+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<html lang="en-US">
2+
<head>
3+
<meta charset="utf-8" />
4+
<title>Microsoft.SqlServer.Types</title>
5+
<style>
6+
body {
7+
background: #fff;
8+
color: #505050;
9+
margin: 20px;
10+
}
11+
12+
#main {
13+
background: #efefef;
14+
padding: 5px 30px;
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
<div id="main">
20+
<h1>Action required to load native assemblies</h1>
21+
<p>
22+
To deploy an application that uses spatial data types to a machine that does not have 'System CLR Types for SQL Server' installed you also need to deploy the native assembly SqlServerSpatial140.dll. Both x86 (32 bit) and x64 (64 bit) versions of this assembly have been added to your project under the SqlServerTypes\x86 and SqlServerTypes\x64 subdirectories. The native assembly msvcr120.dll is also included in case the C++ runtime is not installed.
23+
</p>
24+
<p>
25+
You need to add code to load the correct one of these assemblies at runtime (depending on the current architecture).
26+
</p>
27+
<h2>ASP.NET Web Sites</h2>
28+
<p>
29+
For ASP.NET Web Sites, add the following block of code to the code behind file of the Web Form where you have added Report Viewer Control:
30+
<pre>
31+
Default.aspx.cs:
32+
33+
public partial class _Default : System.Web.UI.Page
34+
{
35+
static bool _isSqlTypesLoaded = false;
36+
37+
public _Default()
38+
{
39+
if (!_isSqlTypesLoaded)
40+
{
41+
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~"));
42+
_isSqlTypesLoaded = true;
43+
}
44+
45+
}
46+
}
47+
</pre>
48+
</p>
49+
<h2>ASP.NET Web Applications</h2>
50+
<p>
51+
For ASP.NET Web Applications, add the following line of code to the Application_Start method in Global.asax.cs:
52+
<pre> SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));</pre>
53+
</p>
54+
<h2>Desktop Applications</h2>
55+
<p>
56+
For desktop applications, add the following line of code to run before any spatial operations are performed:
57+
<pre> SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);</pre>
58+
</p>
59+
</div>
60+
</body>
61+
</html>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

test/GeoJSON.Net.Contrib.MsSqlSpatial.Test/GeoJSON.Net.Contrib.MsSqlSpatial.Test.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<ItemGroup>
7575
<Compile Include="AssemblyInitializer.cs" />
7676
<Compile Include="Properties\AssemblyInfo.cs" />
77+
<Compile Include="SqlServerTypes\Loader.cs" />
7778
<Compile Include="ToGeoJSONGeographyTests.cs" />
7879
<Compile Include="ToSqlGeographyTests.cs" />
7980
<Compile Include="ToSqlGeometryTests.cs" />
@@ -93,6 +94,21 @@
9394
<SubType>Designer</SubType>
9495
</None>
9596
</ItemGroup>
97+
<ItemGroup>
98+
<Content Include="SqlServerTypes\readme.htm" />
99+
<Content Include="SqlServerTypes\x64\msvcr120.dll">
100+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
101+
</Content>
102+
<Content Include="SqlServerTypes\x64\SqlServerSpatial140.dll">
103+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
104+
</Content>
105+
<Content Include="SqlServerTypes\x86\msvcr120.dll">
106+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
107+
</Content>
108+
<Content Include="SqlServerTypes\x86\SqlServerSpatial140.dll">
109+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
110+
</Content>
111+
</ItemGroup>
96112
<Choose>
97113
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
98114
<ItemGroup>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.IO;
3+
using System.Runtime.InteropServices;
4+
5+
namespace SqlServerTypes
6+
{
7+
/// <summary>
8+
/// Utility methods related to CLR Types for SQL Server
9+
/// </summary>
10+
public class Utilities
11+
{
12+
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
13+
private static extern IntPtr LoadLibrary(string libname);
14+
15+
/// <summary>
16+
/// Loads the required native assemblies for the current architecture (x86 or x64)
17+
/// </summary>
18+
/// <param name="rootApplicationPath">
19+
/// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications
20+
/// and AppDomain.CurrentDomain.BaseDirectory for desktop applications.
21+
/// </param>
22+
public static void LoadNativeAssemblies(string rootApplicationPath)
23+
{
24+
var nativeBinaryPath = IntPtr.Size > 4
25+
? Path.Combine(rootApplicationPath, @"SqlServerTypes\x64\")
26+
: Path.Combine(rootApplicationPath, @"SqlServerTypes\x86\");
27+
28+
LoadNativeAssembly(nativeBinaryPath, "msvcr120.dll");
29+
LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial140.dll");
30+
}
31+
32+
private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName)
33+
{
34+
var path = Path.Combine(nativeBinaryPath, assemblyName);
35+
var ptr = LoadLibrary(path);
36+
if (ptr == IntPtr.Zero)
37+
{
38+
throw new Exception(string.Format(
39+
"Error loading {0} (ErrorCode: {1})",
40+
assemblyName,
41+
Marshal.GetLastWin32Error()));
42+
}
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)