Bunu yapmak istediğim bu kodu aldım SQL dize bağlantısı sınayın, ancak bu sorunu çözmem için bana yardım edermisin connection.Open = true
? Zaman ayırdığın için çok teşekkürler.SQL bağlantı dizesi kullanılabilirliğini sınamanın en etkili yolu
private void button1_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection connection = new SqlConnection("Data Source='" + textBox1.Text + "';Initial Catalog='" + textBox2.Text + "';User ID='" + textBox3.Text + "';Password='" + textBox4.Text + "'"))
{
try
{
connection.Open();
if (connection.Open == true) // if connection.Open was successful
{
MessageBox.Show("You have been successfully connected to the database!");
}
else
{
MessageBox.Show("Connection failed.");
}
}
catch (SqlException) { }
}
}
catch (Exception ex)
{
MessageBox.Show("Chyba v přihlášení: " + ex);
}
finally
{
}
}
O diyor ki: Ben bu kod toplam kötü olabileceğini biliyoruz "bunun bir 'methoud grup' olduğundan 'açık' asign Can not", ama bir şekilde bu ele gerekir ve doğru olanı hiçbir fikrim yok yol. Teşekkür ederim.
Bu aslında değil açılmış bağlantı için çalışmıyor şudur: bir özellik sanki sen connection.Open = true
kullandığınız
using (SqlConnection connection = new SqlConnection("Data Source='" + textBox1.Text + "';Initial Catalog='" + textBox2.Text + "';User ID='" + textBox3.Text + "';Password='" + textBox4.Text + "'"))
{
connection.Open();
if (connection.State == ConnectionState.Open)
{
MessageBox.Show("Spojení s databázi problěhlo úspěšně.");
}
connection.Close();
if (connection.State == ConnectionState.Closed)
{
MessageBox.Show("Spojení selhalo");
}
}
'.Open()', bir özellik değil, void döndüren bir ** yöntemidir. Buna bir değer atayamazsınız. Cevabımı gör. – DGibbs