简体   繁体   中英

Xamarin Can't Connect to SQL Database

I have a C# Xamarin Android application which I need to connect to a SQL Server instance accessible over the network.

try
{
      using (SqlConnection cn = new SqlConnection(ConnectionString))
      {
                cn.Open();

                IsConnected = true;
       }
  }
  catch (Exception ex)
  {
        Toast.MakeText(Application.Context, "Error Occuerred: " + ex.Message, ToastLength.Long).Show();
   }

The Connection String is as follows: Data Source=IPAddress;Initial Catalog=DatabaseName;Persist Security Info=True;User ID=SomeUser;Password=SomePassword

I have included the INTERNET and WIFI_State Permissions in the manifest. (To check if wifi is currently turned on and connected to some kind on network)

I am getting an error: Server Does Not Exist or Connection is refused. I can connect my Honeywell Scanning device to the database with the same connection string.

Please NOTE I don not want a web service to handle the SQL connection in order for me to select and update tables.

Wrote an ASP. NET web service which is very efficient and quick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM