Skip to content

DataReader.GetFieldType returned null #71

@vishnu4

Description

@vishnu4

This is basically a copy of #32 . I can provide more info in my case:

.net core 6 project using Microsoft.Data.SqlClient,
Method is:

      public virtual DataTable ExecuteProcedure(string cnnString, string theProcedure, IEnumerable<IDataParameter> theParameters)
       {
           DataTable dt = null;
           using (DataSet ds = new DataSet())
           {
               ds.Locale = System.Globalization.CultureInfo.InvariantCulture;
               using (SqlConnection cnn = new SqlConnection(cnnString))
               {
                   try
                   {
                       cnn.Open();
                       using (SqlCommand cmd = new SqlCommand(theProcedure, cnn))
                       {
                           // cmd.Prepare()	'use for large databases?
                           using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                           {
                               cmd.CommandType = CommandType.StoredProcedure;
                               if (theParameters != null && theParameters.Any())
                               {
                                   foreach (IDataParameter theParam in theParameters)
                                   {
                                           cmd.Parameters.Add(theParam.FormatParamValue());
                                   }
                               }
                               da.Fill(ds);
                           }
                       }
                   }
                   finally
                   {
                       if (cnn != null && cnn.State != ConnectionState.Closed)
                       {
                           cnn.Close();
                       }
                   }
               }
               if (!(ds == null) && !(ds.Tables == null) && (ds.Tables.Count > 0))
               {
                   dt = ds.Tables[0];
               }
           }
           return dt;
       }

if i run this against a stored procedure that's just

create PROCEDURE [dbo].[Organization_List] 
AS
BEGIN
	SET NOCOUNT ON;
SELECT
OrganizationGUID,
OrganizationName,
OrgGeometry
FROM dbo.Organization

END

with a table

CREATE TABLE [dbo].[Organization](
	[OrganizationName] [nvarchar](100) NOT NULL,
	[OrgGeometry] [geometry] NULL,
	[OrganizationGUID] [uniqueidentifier] NOT NULL
GO

and add some fake data

declare @g geometry = geometry::STGeomFromText(
    'POINT (22.9901232886963 87.5953903123242)'
    , 4326);
INSERT INTO Organization (OrganizationName,OrgGeometry,OrganizationGUID) VALUES('Test',@g,newid())

Then you get the error above, with or without installing your package to the application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions