bflattened / bflat

C# as you know it but with Go-inspired tooling (small, selfcontained, and native executables)
GNU Affero General Public License v3.0
3.65k stars 107 forks source link

Support for SQL server (System.Data.SqlClient) #18

Closed ErikNieuwkoop closed 2 years ago

ErikNieuwkoop commented 3 years ago

Hi,

I have a small program that accesses a MS SQLserver database. When compiling with bflat I get the following error "The type name 'SqlConnection' could not be found in the namespace 'System.Data.SqlClient'. This type has been forwarded to assembly 'System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.". The reference is there (see attachment), so I don't understand what is going wrong.

BFlat_error

oyundev commented 3 years ago

To compile this example code:

using System;
using System.Data.SqlClient;
var connectionString = @"Data Source=.\SQLEXPRESS;Integrated Security=SSPI;";
using var sqlcon = new SqlConnection(connectionString);
sqlcon.Open();
Console.WriteLine($"Version: {sqlcon.ServerVersion} State: {sqlcon.State}");
sqlcon.Close();

Under Windows x64, download nuget package: system.data.sqlclient.4.8.2.nupkg from https://www.nuget.org/api/v2/package/System.Data.SqlClient/4.8.2

Using 7zip, extract System.Data.SqlClient.dll (1.023.352 bytes) inside of nuget file: system.data.sqlclient.4.8.2.nupkg->runtimes->win->lib->netcoreapp2.1->System.Data.SqlClient.dll

Now you can successfully (with some warnings) compile...

C:\Temp\sql>bflat.exe build sqlapp.cs -r .\System.Data.SqlClient.dll
ILC: Trim analysis warning IL2026: ..........

If you now try to run the executable it might fail because of a native dependency of System.Data.SqlClient.

C:\Temp>sqlapp.exe
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'sni.dll': The specified module could not be found.

Download nuget package: runtime.win-x64.runtime.native.system.data.sqlclient.sni.4.4.0.nupkg
from https://www.nuget.org/api/v2/package/runtime.win-x64.runtime.native.System.Data.SqlClient.sni/4.4.0

Using 7zip, extract sni.dll (160.040 bytes) and then place it the same folder with your executable.

C:\Temp\sql>sqlapp.exe
Version: 15.00.2000 State: Open