none
SqlConnection.GetSchema() Throws Exception in Release Build RRS feed

  • Question

  • In a UWP app, SqlConnection.GetSchema(string, string[] args) will throw an "ArgumentNull" exception in a release build, with or without code optimization. Same exact GetSchema() call works fine in debug builds. I can also otherwise successfully connect and query the server (a remote machine). Tried SQL Server versions 2012 & 2017.

    Specific Exception is a System.AggregateException, with an Inner Exception of ArgumentNull: "value cannot be null. Parameter name: xmlStream."

    Using Visual Studio 16.1.5 and Microsoft.NETCore.UniversalWindowsPlatform 6.2.8

    Stack trace:

    at System.Data.ProviderBase.DbMetaDataFactory..ctor(Stream xmlStream, String serverVersion, String normalizedServerVersion)
    at System.Data.SqlClient.SqlConnectionFactory.CreateMetaDataFactory(DbConnectionInternal internalConnection, Boolean& cacheMetaDataFactory)
    at System.Data.ProviderBase.DbConnectionFactory.GetMetaDataFactory(DbConnectionPoolGroup connectionPoolGroup, DbConnectionInternal internalConnection)
    at System.Data.ProviderBase.DbConnectionInternal.GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, String collectionName, String[] restrictions)
    at System.Data.SqlClient.SqlConnection.GetSchema(String collectionName, String[] restrictionValues)
    at System.Data.SqlClient.SqlConnection.GetSchema(String collectionName)
    at AklauSimpleQueryUWP.Data.CrudSQL.GetSchemaTables(DataTable& pDataTable) in D:\Users\ricci\Documenti\Visual Studio 2019\Projects\Aklau_Simple_Query_UWP\Data\CrudSQL.cs:line 119


    eidon

    Saturday, July 6, 2019 10:18 PM

All replies

  • could you post some code?
    Saturday, July 6, 2019 11:16 PM
  • The code is very simple:        

    internal bool GetSchemaTables(out DataTable pDataTable) {
                pDataTable = null;

                try {
                    using (System.Data.SqlClient.SqlConnection objSqlConnection =
                            new System.Data.SqlClient.SqlConnection(new Data.CrudSQL(base.Server, base.Database, base.User, base.Password).cnnString(1))) {

                        objSqlConnection.Open();
                        pDataTable = objSqlConnection.GetSchema(System.Data.SqlClient.SqlClientMetaDataCollectionNames.Tables);

                        return true;
                    }
                }
                catch (Exception ex) {
                    base.Error = ex.Message;
                    return false;
                }
            }


    eidon

    Saturday, July 6, 2019 11:35 PM
  • Hi eidon,

    Per the code script and the error message above, the method "SqlConnection.GetSchema" should have two parameters. For this purpose, you need to read this article to try to solve your issue.

    SqlConnection.GetSchema Method

    Best Regards,

    Will


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 8, 2019 8:22 AM
    Moderator
  • Hi Will, 

    I tried to execute the first call of the example, conn.GetSchema ("MetaDataCollections"), but the result is always the same. It works in debug but generates exception in relase.


    eidon

    Monday, July 8, 2019 12:05 PM
  • Hi Will, 

    I tried to execute the first call of the example, conn.GetSchema ("MetaDataCollections"), but the result is always the same. It works in debug but generates exception in relase.


    eidon

    Hi eidon,

    Thanks for your reply.

    Yes. conn.GetSchema() method is same as conn.GetSchema("MetaDataCollections"), which is mentioned at

    How to Get Schema Information from Database. How to get desired schema information from database depends on your needs. You could follow this to achieve it.

    Best Regards,

    Will


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 9, 2019 10:10 AM
    Moderator
  • Hi Will,

    Maybe I explained myself wrongly ... all calls to GetSchema() work in Debug but generate the exception above when run in relase.


    eidon

    Wednesday, July 10, 2019 5:26 PM
  • Hi Will,

    Maybe I explained myself wrongly ... all calls to GetSchema() work in Debug but generate the exception above when run in relase.


    eidon

    I guess you haven't installed .NET Core  runtime or .NET Framework runtime, please download and install it, then see if it works.

    Reference

    SqlConnection.GetSchema Method (Applies to)

    .NET Core 3.0.0 Preview 6 - June 12, 2019

    .NET Framework

    Best Regards,

    Will


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 11, 2019 8:13 AM
    Moderator
  • I think it could be a bug in Sql client. I found the same exception in github - dotnet / SqlClient:

    https://github.com/dotnet/SqlClient/issues/46

    What do you think about it ? I think that's my case


    eidon

    Thursday, July 11, 2019 7:55 PM
  • I think it could be a bug in Sql client. I found the same exception in github - dotnet / SqlClient:

    https://github.com/dotnet/SqlClient/issues/46

    What do you think about it ? I think that's my case


    eidon

    Yes, it is exactly same as yours. So you need to wait for confirmation from develop team.

    Best Regards,

    Will


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 12, 2019 7:45 AM
    Moderator