0
How can I connect to SQL with connectionstring in Appconfig?
I did so, but I wish it could be for Appconfig, how can I do?
private void button1_Click(object sender, EventArgs e)
{
string connectionString = @"Data Source=SQL;Initial Catalog=Banco;Persist Security Info=True;User ID=sa;Password=Senha";
SqlConnection con = new SqlConnection(connectionString);
try
{
con.Open();
MessageBox.Show("Conectado com sucesso");
}
catch
{
MessageBox.Show("Erro ao conectar");
}
}
I did this and my program closes when I click the button
– Leonardo Araujo
This is the default code for this operation, confirm that the names are correct and the connection string as well. Throughout debug the code and see if it throws any error message.
– MurariAlex
Put the break-point and see and when the program closes
– MurariAlex
I’ve got it, thank you.
– Leonardo Araujo