Connecting System.Data.Sqlclient with Intance

Hello everyone, (and yes I'm using google translator) I'm doing a project in Xamarin Forms and System.Data.Sqlclient to connect to a database server 2008 r2, I'm able to connect normally in the default instance, but trying SQL Server Browser has been started, but the SQL Server Browser is started normally, and in the SQL of the computer it is also connecting as well.

My code:

string StringConnection = string.Format("Data Source={0};Initial Catalog={1};User={2};Password={3};",
ServidorEntry.Text, BancoEntry.Text, UsuarioEntry.Text, SenhaEntry.Text);

try
{
int count = 0;
using (SqlCommand command = new SqlCommand(select, con.CNN(StringConnection)))
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
count++;

        NomeFantasiaEntry.Text = reader.GetValue(0).ToString();
        CNPJEntry.Text = reader.GetValue(1).ToString();

        break;
    }
}

UserDialogs.Instance.HideLoading();


if (count > 0)
{
    testado = 1;
}
else
{
    DisplayAlert("Servidor não encontrado", "Verifique os campos e tente novamente!", "OK");
    testado = 0;
}

}
catch (Exception ex)
{
UserDialogs.Instance.HideLoading();
DisplayAlert("Erro", "Verifique sua conexão!\n" + StringConnection + "\n" + ex.Message, "OK");
testado = 0;
}

Best Answer

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    @zanettijm said:
    Hello everyone, (and yes I'm using google translator) I'm doing a project in Xamarin Forms and System.Data.Sqlclient to connect to a database server 2008 r2, I'm able to connect normally in the default instance, but trying SQL Server Browser has been started, but the SQL Server Browser is started normally, and in the SQL of the computer it is also connecting as well.

    My code:

    string StringConnection = string.Format("Data Source={0};Initial Catalog={1};User={2};Password={3};",
    ServidorEntry.Text, BancoEntry.Text, UsuarioEntry.Text, SenhaEntry.Text);

    try
    {
    int count = 0;
    using (SqlCommand command = new SqlCommand(select, con.CNN(StringConnection)))
    using (SqlDataReader reader = command.ExecuteReader())
    {
    while (reader.Read())
    {
    count++;

          NomeFantasiaEntry.Text = reader.GetValue(0).ToString();
          CNPJEntry.Text = reader.GetValue(1).ToString();
    
          break;
        }
    }
    
    UserDialogs.Instance.HideLoading();
    
    
    if (count > 0)
    {
        testado = 1;
    }
    else
    {
        DisplayAlert("Servidor não encontrado", "Verifique os campos e tente novamente!", "OK");
        testado = 0;
    }
    

    }
    catch (Exception ex)
    {
    UserDialogs.Instance.HideLoading();
    DisplayAlert("Erro", "Verifique sua conexão!\n" + StringConnection + "\n" + ex.Message, "OK");
    testado = 0;
    }

    Hi.
    Have you been able to connect to SqlSErver remotely?
    Have you installed System.Data.SqlClient directly on Xamarin Forms project?
    It's a Windows app or are you using also on Android?

Sign In or Register to comment.