-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot connect to a sql database using system.data.sqlclient and native aot win 64 publish #89782
Comments
Tagging subscribers to this area: @DavoudEshtehari, @David-Engel, @JRahnama Issue DetailsHello, using .net 8 preview 6 and trying to use the latest system.data.sqlclient nuget package to connect to a sql database. the project runs fine from visual studio, connects to my database using sql server id and password and returns data. i am building off the new aot api project created from command line. However after publish and running the exe in the publish folder i put a try catch on my db connection to catch the error and get this. Mind you its not my connection string as that works fine running the same app from visual studio.
|
When you publish the app for NativeAOT - does it produce warnings? |
No warnings are produced. The publish goes through fine but the executable
produces the error I gave.
…On Tue, Aug 1, 2023 at 5:02 PM Vitek Karas ***@***.***> wrote:
When you publish the app for NativeAOT - does it produce warnings?
I don't think SqlClient is AOT compatible yet.
—
Reply to this email directly, view it on GitHub
<#89782 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB7DCF6BZZWDA4LKAJ6G433XTFVGHANCNFSM6AAAAAA273CNL4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Any chance for a repro? Or at least how you're using SqlClient. |
It's likely that the native component required for network connectivity has not been restored, look for System.Data.SqlClient.*.sni.dll. Also, as @vitek-karas says System.Data.SqlClient has not been audited and made AOT safe because it no longer ships as part of the framework. The replacement is Microsoft.Data.SqlClient and work to make it AOT safe is on-going. |
In the publish folder for the executable there is an sni.dll that is there along with the executable. Everything was restored prior to publish but it is still failing.Thank you,Jason DurnilOn Aug 1, 2023, at 8:11 PM, Wraith ***@***.***> wrote:
It's likely that the native component required for network connectivity has not been restored, look for System.Data.SqlClient.*.sni.dll. Also, as @vitek-karas says System.Data.SqlClient has not been audited and made AOT safe because it no longer ships as part of the framework. The replacement is Microsoft.Data.SqlClient and work to make it AOT safe is on-going.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Ok, maybe getting somewhere, I switched to Microsoft.data.sqlclient and am now getting the following error which someone may be able to tell me how to fix, the Microsoft.data.sqlclient.sni.dll is showing up in the publish folder. I am now getting this Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name') at System.Globalization.CultureInfo.GetCultureInfo(String) + 0x189 |
Actually, thanks for all the help again, this was set to true in my project file |
Set You can also try it with AOT and see what works. It's been at least partially annotated and using most features should work. If there are things that don't work open issues on the the https://github.com/dotnet/SqlClient repo with a reproduction and it'll get looked into. |
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsHello, using .net 8 preview 6 and trying to use the latest system.data.sqlclient nuget package to connect to a sql database. the project runs fine from visual studio, connects to my database using sql server id and password and returns data. i am building off the new aot api project created from command line. However after publish and running the exe in the publish folder i put a try catch on my db connection to catch the error and get this. Mind you its not my connection string as that works fine running the same app from visual studio.
|
Seems unusual that AOT can't handle this. Here's a repro (different stack, but I suspect that's just due to my connection string). That'll fail with
Seems odd that we can't load sni.dll - it's present and next to the app. |
It is odd. I know that Microsoft.Data.SqlClient got some work in this area though so it's better to move to it. /cc @David-Engel in case you want to investigate |
The S.D.SqlClient NuGet package is legacy. It was a bridge for people coming from .NET Framework to .NET Core. I wouldn't be surprised if there are issues with it that mean it will never be suitable against .NET 8. If you are on a modern version of .NET, move to M.D.SqlClient. |
I create #89874 to look into the native library loading issue in NativeAOT. |
I’m thought my messages made it over. It is all working now. Thanks again.Thank you,Jason DurnilOn Aug 2, 2023, at 3:57 PM, Vitek Karas ***@***.***> wrote:
I create #89874 to look into the native library loading issue in NativeAOT.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
This can be likely worked around by adding |
I didn’t need to do that. I just switched to Microsoft.Data.SqlClient
…On Wed, Aug 2, 2023 at 4:51 PM Michal Strehovský ***@***.***> wrote:
Seems unusual that AOT can't handle this. Here's a repro (different stack,
but I suspect that's just due to my connection string).
This can be likely worked around by adding <ItemGroup><DirectPInvoke
Include="sni" /></ItemGroup> to the project file for now.
—
Reply to this email directly, view it on GitHub
<#89782 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB7DCF6UP3GB3ZIWCGNXGIDXTK4T7ANCNFSM6AAAAAA273CNL4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Thank you for letting us know. |
Hello, using .net 8 preview 6 and trying to use the latest system.data.sqlclient nuget package to connect to a sql database. the project runs fine from visual studio, connects to my database using sql server id and password and returns data. i am building off the new aot api project created from command line. However after publish and running the exe in the publish folder i put a try catch on my db connection to catch the error and get this. Mind you its not my connection string as that works fine running the same app from visual studio.
A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x14d
at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnNonGCStaticBase(StaticClassConstructionContext*, IntPtr) + 0xd
at System.Data.SqlClient.TdsParser..ctor(Boolean, Boolean) + 0x60
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo, String, SecureString, Boolean, SqlConnectionString, SqlCredential, TimeoutTimer) + 0x144
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer, SqlConnectionString, SqlCredential, String, SecureString, Boolean) + 0x1b2
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity, SqlConnectionString, SqlCredential, Object, String, SecureString, Boolean, SqlConnectionString, SessionData, Boolean, String) + 0x362
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions, DbConnectionPoolKey, Object, DbConnectionPool, DbConnection, DbConnectionOptions) + 0x2e7
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool, DbConnection, DbConnectionOptions, DbConnectionPoolKey, DbConnectionOptions) + 0x33
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection, DbConnectionOptions, DbConnectionInternal) + 0x2a8
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection, DbConnectionOptions, DbConnectionInternal) + 0x5e
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection, UInt32, Boolean, Boolean, DbConnectionOptions, DbConnectionInternal&) + 0x35b
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection, TaskCompletionSource
1, DbConnectionOptions, DbConnectionInternal&) + 0x8b at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection, TaskCompletionSource
1, DbConnectionOptions, DbConnectionInternal, DbConnectionInternal&) + 0x16cat System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection, DbConnectionFactory, TaskCompletionSource
1, DbConnectionOptions) + 0x118 at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource
1) + 0x101at System.Data.SqlClient.SqlConnection.Open() + 0xf8
at MyFirstAotWebApi.SQLQuery.GetTodos() + 0x9c
The text was updated successfully, but these errors were encountered: