Skip to content

Cannot connect to a sql database using system.data.sqlclient and native aot win 64 publish #89782

@jdurnil

Description

@jdurnil

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, TaskCompletionSource1, DbConnectionOptions, DbConnectionInternal&) + 0x8b at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection, TaskCompletionSource1, DbConnectionOptions, DbConnectionInternal, DbConnectionInternal&) + 0x16c
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection, DbConnectionFactory, TaskCompletionSource1, DbConnectionOptions) + 0x118 at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1) + 0x101
at System.Data.SqlClient.SqlConnection.Open() + 0xf8
at MyFirstAotWebApi.SQLQuery.GetTodos() + 0x9c

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions