dotnet / SqlClient

Microsoft.Data.SqlClient provides database connectivity to SQL Server for .NET applications.
MIT License
839 stars 280 forks source link

ConnectionString property throws null reference exception under MSI deployment, but not ClickOnce or Locally #1855

Open statler opened 1 year ago

statler commented 1 year ago

Describe the bug

When deployed as an MSI (but not when run locally or when deplyed with ClickOnce), Microsoft.Data.SqlClient throws a null reference exception when accessing the ConnectionString property. This problem goes away when I clone the Microsoft.Data.SqlClient and directly include it in the project. It only occurs when using the library as a reference from Nuget, and only when deployed as an MSI.

This leads me to think it may be some kind of reference issue. Both the library where the exception is thrown, and the master project have reverences to Microsoft.Data.SqlClient and Microsoft.Data.SqlClient.SNI

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.Data.SqlClient
StackTrace:
at Microsoft.Data.SqlClient.SqlConnection.get_ConnectionString()
at DevExpress.Xpo.DB.ConnectionProviderSql…ctor(IDbConnection connection, AutoCreateOption autoCreateOption)
at DevExpress.Xpo.DB.MSSqlConnectionProvider…ctor(IDbConnection connection, AutoCreateOption autoCreateOption)
at DevExpress.Xpo.DB.MSSqlConnectionProvider.CreateProviderFromString(String connectionString, AutoCreateOption autoCreateOption, IDisposable[]& objectsToDisposeOnDisconnect)
at DevExpress.Xpo.DB.DataStoreBase.QueryDataStore(String providerType, String connectionString, AutoCreateOption defaultAutoCreateOption, IDisposable[]& objectsToDisposeOnDisconnect)
at DevExpress.Xpo.XpoDefault.GetConnectionProvider(String connectionString, AutoCreateOption defaultAutoCreateOption, IDisposable[]& objectsToDisposeOnDisconnect)
at DevExpress.Xpo.XpoDefault.GetDataLayer(String connectionString, XPDictionary dictionary, AutoCreateOption defaultAutoCreateOption, IDisposable[]& objectsToDisposeOnDisconnect)
at DevExpress.Xpo.XpoDefault.GetDataLayer(String connectionString, AutoCreateOption defaultAutoCreateOption)
at CivilPro.InfrastructureC.Database.XPODBInitializer.IsSchemaPresent() in C:\Users\dennisg\source\repos\CivilProv9\CivilPro.InfrastructureC\Database\XPODBInitializer.cs:line 224

To reproduce

This is quite a specific edge case - I am hoping this is relatively straight forward to the authors. It would take my whole project to demsontrate I think, and that is huge :(

Expected behavior

The application should run under MSI deployment like it does under ClickOnce, and under local.

Further technical details

Microsoft.Data.SqlClient version: (found on the nuget or Microsoft.Data.SqlClient.dll) 5.01 .NET target: Framework 4.7.1 SQL Server version: (e.g. SQL Server 2017) SQL 2019 Operating system: Win10

lcheunglci commented 1 year ago

Hi @statler, could you provide us with the connection string?

lcheunglci commented 1 year ago

also, what are you using for generating the MSI?

WolvenRA commented 1 year ago

I'm having the exact same problem. I'm using Microsoft's Setup project in VS2019 and VS generates the MSI when I build the solution.

WolvenRA commented 1 year ago

PS.. The program runs fine from the VS IDE but when I install it (on the same computer running the IDE) it fails to run. It creates 2 errors in the event log. 1 says the source is .net Runtime and that it is a NullReferenceException at Microsoft.Data.SqlClient.SqlConnectionEncryption.op_Implicit(Boolean). the 2nd says the "Faulting module name" is KERNELBASE.dll version 10.0.19041.2846 Exception code 0xe0434352 and the Faulting Application is my executable's name.