Skip to content
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

Fill DataTable throws DataReader.GetFieldType null #76

Open
mxcolin opened this issue Aug 30, 2022 · 0 comments
Open

Fill DataTable throws DataReader.GetFieldType null #76

mxcolin opened this issue Aug 30, 2022 · 0 comments

Comments

@mxcolin
Copy link

mxcolin commented Aug 30, 2022

At first I tried referencing your project through nuget but whatever I did, calling Fill on a DataTable always returned a null on the Geometry column, same for a DataReader with GetFieldType. I saw both of these issues here but you couldn't reproduce them, so I thought I would clone your whole repo to see what was going on. The bizarre thing is that it works perfectly in a Test Project, so I stripped the included test project all back to a single test with my code and it still worked, the identical code in my Console app fails as above. I assumed there was something funky with the way your test project was set up so I created a whole new test project, yet again I can debug into the test and it works, but not in the Console app. So, if I take your original solution and create 2 net6.0 projects, one a test and the other a console app, then simply add the project reference, I have 2 different behaviors. I can't explain it. Create a Console Application and add a Project reference to the main Microsoft.SqlServer.Types project and add the following code:

SqlConnection connection = new SqlConnection(".......<your connection string>...");
connection.Open();

string sql = "SELECT * FROM [schema].[table_with_geometry_column]";
SqlCommand command = new SqlCommand(sql, connection);

SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
connection.Close();

It will throw a "System.InvalidOperationException: 'DataReader.GetFieldType(3) returned null."

Error on the call to Fill, where 3 is the ordinal of my geometry column.

Run this exact same code in a TestMethod and it works as expected. Cannot for the life of me figure out what's happening???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant