Skip to content

.NET MAUI SQL Server doesn't work in release mode #2338

Closed

Description

@hammadkhandev888

Describe the bug

A clear and concise description of what the bug is.
I am using .NET MAUI. I connect to SQL Server using an IP address. I have a specific scenario that requires me to connect to SQL Server within my .NET MAUI application. It works fine in debug mode, and I can connect to SQL Server. However, I am unable to connect to it in release mode.

Connection String

Server=Server,1434;Database=DB;User ID=penn;Password=asdaf;Encrypt=false;TrustServerCertificate=true;

Could you please help me?

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception message:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)
Stack trace:


### To reproduce

Create .NET MAUi App
Add Microsoft.Data.SqlClient
Add SqlConnection and enter your connection string using IP port,
Run the app on android in release mode

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.



### Expected behavior
A clear and concise description of what you expected to happen.
It should alow me to connect to SQL Server database as it is in Debug Mode.

### Further technical details
Microsoft.Data.SqlClient version: (found on the nuget or Microsoft.Data.SqlClient.dll)
.NET target: .NET8
SQL Server version: SQL Express 2022
Operating system: Window 11

**Additional context**
I am getting this in Event Viewer
The SQL Server Network Interface library could not register the Service Principal Name (SPN) [ MSSQLSvc/DESKTOP-TKH5FGS:1433 ] for the SQL Server service. Windows return code: 0xffffffff, state: 63. Failure to register a SPN might cause integrated authentication to use NTLM instead of Kerberos. This is an informational message. Further action is only required if Kerberos authentication is required by authentication policies and if the SPN has not been manually registered.

Activity

  1. kf-gonzalez commented on Feb 6, 2024

    @kf-gonzalez

    Can you you provide a packet capture that works for it, and one that it doesn't. For sanity check, can you check your app settings between release and debug to make sure there is no difference

  2. hammadkhandev888 commented on Feb 7, 2024

    @hammadkhandev888
    Author

    Thank you for your comment. I have resolved the issue.

    Here's what I did:

    1. Updated the Nuget to the latest pre-release
    2. Added the INTERNET permission in the AndroidMenifest.xml file

    After these changes, it worked. I will now close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions