-
Notifications
You must be signed in to change notification settings - Fork 321
Open
Labels
Waiting for Customer ⏳Issues/PRs waiting for user response/action.Issues/PRs waiting for user response/action.
Description
Describe the bug
I upgraded to Microsoft.Data.SqlClient 6.1.3 and now getting "Object reference not set to an instance of an object" on every data call.
The SQLConnection object initializes but when checking connection.State or connection.ConnectionString, it throws a null reference. I believe this is the issue.
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()
In the appsettings.json:
"db": "Data Source=MyDB;Initial Catalog=MyDB; user id=MyUser; Password=MyPassword;TrustServerCertificate=True"
Project settings
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.1.3" />
Exception message:
Stack trace:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.Data.SqlClient
StackTrace:
at Microsoft.Data.SqlClient.SqlDataAdapter.System.Data.IDbDataAdapter.get_SelectCommand()
To reproduce
connection = new SqlConnection(GetConnectionStr());
connection.Open(); // error occurs testing any property in Immediate window, so I think the error is here.
string SQL = string.Format("select * from {0}", tableName);
SqlCommand cmd = new SqlCommand(SQL, connection);
cmd.CommandType = CommandType.Text;
DataTable retn = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(retn);Expected behavior
It should fill the DataTable as it performed many times before.
Further technical details
Microsoft.Data.SqlClient version: 6.1.3
.NET target: NET 6.0, DotNetCoreApp 6.0.36, AspNetCore 6.0.36
SQL Server version: 13.0.7070.4
Operating system: Windows 11
Additional context
Add any other context about the problem here.
Metadata
Metadata
Assignees
Labels
Waiting for Customer ⏳Issues/PRs waiting for user response/action.Issues/PRs waiting for user response/action.