Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I have problem with connection to database XAMARINE forms

Normal C# windows form app work with this string

SSMS work normal with this credential

C#
string connectionString = "Data Source=sql.bss-solution.info,1433;Initial Catalog='ABC 2023';User ID=admin;Password=somepass;Connect Timeout=60";


Xamarine Forms have error

Maybe in database name have space ABC 2023, maybe need 'ABC 2023' or "ABC 2023"  or [ABC 2023] (I try all solution not work)


Some help?

Thank you

ERROR IS:

System.InvalidOperationException: 'Internal connection fatal error.'


What I have tried:

Maybe in database name have space ABC 2023, maybe need 'ABC 2023' or "ABC 2023" or [ABC 2023] (I try all solution not work)
Posted
Updated 9-Nov-23 8:00am
v4

As is stated here[^] and here[^] you cannot connect Xamarin form(s) to sql database directly.
 
Share this answer
 
v2
Firstly make sure you have the necessary permissions and that your SQL Server is configured to allow connections from your Xamarin Forms app.

Then make sure you have the correct dependencies and configurations in your Xamarin Forms project. Ensure that you are using the right SQL Server package or library for your Xamarin Forms.

To set up a connection in your Xamarin Forms using ADO.NET as for instance you will use as an example the following (as you supplied no sample code for us to make sense) -

C#
using System;
using System.Data.SqlClient;

namespace YourNamespace
{
    public class DatabaseHandler
    {
        private static string connectionString = "Data Source=sql.bss-solution.info,1433;Initial Catalog=ABC 2023;User ID=admin;Password=somepass;Connect Timeout=60";

        public void ConnectToDatabase()
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    //Message if connection successful, you can perform database operations here...
                }
            }
            catch (Exception ex)
            {
                //Handle any exceptions/errors, log them, or display an error message...
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900