0

This is my connection string:

private static string connectionString = @"Data Source=DESKTOP-NAME\PRODUCTDB;User ID=USER;Password=********;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
SqlConnection connection;

This is my function:

public void checkForProduct(Int64 Scanned_EAN)
{
    using (connection = new SqlConnection(connectionString))
    {
        // Open the connection, so we can perform SQL commands
        connection.Open();                
    }
}

If I try to run this, I get the cannot connect to SQL Server browser. I have searched for 10 hours today and I can't seem to find the answer. The database is running, the server browser is running, I have let them through firewall, forwarded TCP, and UDP port for SQL. I am using SSMS, and I have managed to connect to the database using the server explorer in Visual Studio. But I can't connect via code.

Dale K
  • 25,246
  • 15
  • 42
  • 71
Wilicious
  • 15
  • 4
  • 1
    It is a horrible, terrible, very bad idea to connect to your DB server directly from a mobile client. Please don't do this. But if you insist on doing it this way, it's unlikely your mobile device knows what "DESKTOP-NAME" is - use the IP instead. – Jason Dec 02 '20 at 21:35
  • I am aware of this, it's only for home use/fun/learning really. – Wilicious Dec 03 '20 at 07:56

2 Answers2

0

Try using IP address of your machine instead of "DESKTOP-NAME".

  • I tried doing: "Server = IP, por; Databse=...; User Id=...; Password= ...;" then I got TCP providor error: 40. Could not open connection to SQL server – Wilicious Dec 03 '20 at 07:58
  • And if i connect to the database via server explorer and then use that connection string, I get an error saying the connection string is invalid... – Wilicious Dec 03 '20 at 08:03
0

I expend a couple days in order to fix it:

firstable you need to able the remote connections to your sql server instance:

  1. https://www.youtube.com/watch?v=5UkHYNwUtCo

Therefore able the user sa in sql server: 2. https://www.youtube.com/watch?v=1JFKUwT739Q

  1. Finally solve the final bug related with the encode with this: Xamarin - Encoding Error 1252 data could not be found

Here is my connection string example: connectionString = "Data Source=192.168.56.1,49170;Initial Catalog=Fundacion_feb2023;user id=sa;password=*****;";