Skip to content

Commit b69c324

Browse files
committed
Added SqlServerTypes & updated ChangesLog & ver
1 parent b1c8fd1 commit b69c324

12 files changed

+271
-4
lines changed

App.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
55
</startup>
66
</configuration>

CAMOsoft/CAMOsoft.DbUtils/CAMOsoft.DbUtils.csproj

+23-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>CAMOsoft.DbUtils</RootNamespace>
1212
<AssemblyName>CAMOsoft.DbUtils</AssemblyName>
13-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<StartupObject>
1616
</StartupObject>
@@ -85,8 +85,12 @@
8585
<Compile Include="DbSession.cs" />
8686
<Compile Include="MsSqlCmd.cs" />
8787
<Compile Include="MsSqlSession.cs" />
88+
<Compile Include="SqlServerTypes\Loader.cs" />
8889
</ItemGroup>
8990
<ItemGroup>
91+
<Reference Include="Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
92+
<HintPath>..\..\packages\Microsoft.SqlServer.Types.14.0.1016.290\lib\net40\Microsoft.SqlServer.Types.dll</HintPath>
93+
</Reference>
9094
<Reference Include="System" />
9195
<Reference Include="System.Data" />
9296
<Reference Include="System.Security" />
@@ -109,4 +113,22 @@
109113
<Install>true</Install>
110114
</BootstrapperPackage>
111115
</ItemGroup>
116+
<ItemGroup>
117+
<Content Include="SqlServerTypes\readme.htm" />
118+
<Content Include="SqlServerTypes\x64\msvcr120.dll">
119+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
120+
</Content>
121+
<Content Include="SqlServerTypes\x64\SqlServerSpatial140.dll">
122+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
123+
</Content>
124+
<Content Include="SqlServerTypes\x86\msvcr120.dll">
125+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
126+
</Content>
127+
<Content Include="SqlServerTypes\x86\SqlServerSpatial140.dll">
128+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
129+
</Content>
130+
</ItemGroup>
131+
<ItemGroup>
132+
<None Include="packages.config" />
133+
</ItemGroup>
112134
</Project>
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+
}
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.SqlServer.Types" version="14.0.1016.290" targetFramework="net461" />
4+
</packages>

ChangesLog.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
SQLPlayer Data Script Writer - Changes Log
22
==========================================
33

4+
ver.2.3 @ 02/12/2020
5+
- Support for Temporal tables (#10)
6+
- Support for Time data type (#14)
7+
- Fixed: Showing the wrong number of rows in a table (#12)
8+
49
ver.2.2 @ 12/06/2020
510
- Support for Binary and Varbinary
611

DataScriptWriter.csproj

+19-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>DataScriptWriter</RootNamespace>
1111
<AssemblyName>DataScriptWriter</AssemblyName>
12-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<SccProjectName>SAK</SccProjectName>
1515
<SccLocalPath>SAK</SccLocalPath>
@@ -50,6 +50,9 @@
5050
<Reference Include="DevExpress.XtraGrid.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
5151
<Reference Include="DevExpress.XtraLayout.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
5252
<Reference Include="DevExpress.XtraPrinting.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
53+
<Reference Include="Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
54+
<HintPath>packages\Microsoft.SqlServer.Types.14.0.1016.290\lib\net40\Microsoft.SqlServer.Types.dll</HintPath>
55+
</Reference>
5356
<Reference Include="System" />
5457
<Reference Include="System.Core" />
5558
<Reference Include="System.Xml.Linq" />
@@ -85,6 +88,7 @@
8588
<Compile Include="Properties\AssemblyInfo.cs" />
8689
<Compile Include="ScriptWriter.cs" />
8790
<Compile Include="ScriptObject.cs" />
91+
<Compile Include="SqlServerTypes\Loader.cs" />
8892
<EmbeddedResource Include="ConnectDbForm.resx">
8993
<DependentUpon>ConnectDbForm.cs</DependentUpon>
9094
</EmbeddedResource>
@@ -105,6 +109,7 @@
105109
<DependentUpon>Resources.resx</DependentUpon>
106110
<DesignTime>True</DesignTime>
107111
</Compile>
112+
<None Include="packages.config" />
108113
<None Include="Properties\Settings.settings">
109114
<Generator>SettingsSingleFileGenerator</Generator>
110115
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -126,6 +131,19 @@
126131
<ItemGroup>
127132
<Content Include="Resources\if_Archive_box_data_file_storage_1886362.ico" />
128133
<Content Include="Resources\data_backup.ico" />
134+
<Content Include="SqlServerTypes\readme.htm" />
135+
<Content Include="SqlServerTypes\x64\msvcr120.dll">
136+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
137+
</Content>
138+
<Content Include="SqlServerTypes\x64\SqlServerSpatial140.dll">
139+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
140+
</Content>
141+
<Content Include="SqlServerTypes\x86\msvcr120.dll">
142+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
143+
</Content>
144+
<Content Include="SqlServerTypes\x86\SqlServerSpatial140.dll">
145+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
146+
</Content>
129147
<None Include="Resources\if_script_lightning_36406.png" />
130148
<None Include="Resources\if_exit_6035.png" />
131149
<None Include="Resources\if_connect_established_1721.png" />

Program.cs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ static class Program
1414
[STAThread]
1515
static void Main()
1616
{
17+
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
18+
1719
Application.EnableVisualStyles();
1820
Application.SetCompatibleTextRenderingDefault(false);
1921
Application.Run(new frmMain());

Properties/Settings.Designer.cs

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SqlServerTypes/Loader.cs

+45
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+
}

SqlServerTypes/readme.htm

+61
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>

packages.config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.SqlServer.Types" version="14.0.1016.290" targetFramework="net472" />
4+
</packages>

0 commit comments

Comments
 (0)