File tree Expand file tree Collapse file tree 3 files changed +20
-8
lines changed
src/Microsoft.Data.SqlClient
netcore/src/Microsoft/Data/SqlClient
netfx/src/Microsoft/Data/SqlClient
tests/ManualTests/SQL/DataReaderTest Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -1476,7 +1476,7 @@ public override DataTable GetSchemaTable()
14761476 Debug . Assert ( null != _metaData . schemaTable , "No schema information yet!" ) ;
14771477 }
14781478 }
1479- return _metaData ? . schemaTable ;
1479+ return _metaData ? . schemaTable ?? new DataTable ( ) ;
14801480 }
14811481 finally
14821482 {
Original file line number Diff line number Diff line change @@ -1667,17 +1667,12 @@ override public DataTable GetSchemaTable()
16671667 {
16681668 if ( null != this . MetaData )
16691669 {
1670-
16711670 _metaData . schemaTable = BuildSchemaTable ( ) ;
16721671 Debug . Assert ( null != _metaData . schemaTable , "No schema information yet!" ) ;
16731672 // filter table?
16741673 }
16751674 }
1676- if ( null != _metaData )
1677- {
1678- return _metaData . schemaTable ;
1679- }
1680- return null ;
1675+ return _metaData ? . schemaTable ?? new DataTable ( ) ;
16811676 }
16821677 finally
16831678 {
Original file line number Diff line number Diff line change @@ -36,7 +36,6 @@ public static void LoadReaderIntoDataTableToTestGetSchemaTable()
3636 [ CheckConnStrSetupFact ]
3737 public static void MultiQuerySchema ( )
3838 {
39- SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder ( DataTestUtility . TCPConnectionString ) ;
4039 using ( SqlConnection connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
4140 {
4241 connection . Open ( ) ;
@@ -65,7 +64,25 @@ public static void MultiQuerySchema()
6564 }
6665 }
6766
67+ [ CheckConnStrSetupFact ]
68+ public static void GetSchemaTable_returns_null_when_no_resultset ( )
69+ {
70+ using ( SqlConnection connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
71+ {
72+ connection . Open ( ) ;
6873
74+ using ( SqlCommand command = connection . CreateCommand ( ) )
75+ {
76+ command . CommandText = "SELECT 1" ;
77+ using ( SqlDataReader reader = command . ExecuteReader ( ) )
78+ {
79+ reader . NextResult ( ) ;
80+ Assert . NotNull ( reader . GetSchemaTable ( ) ) ;
81+ }
82+ }
83+ }
84+ }
85+
6986 // Checks for the IsColumnSet bit in the GetSchemaTable for Sparse columns
7087 [ CheckConnStrSetupFact ]
7188 public static void CheckSparseColumnBit ( )
You can’t perform that action at this time.
0 commit comments