I'm trying to make a application that connect to a SQL Server database with connection values from textbox but when I try connect it gives me connection error
error code: 40 - Could not open a connection to SQL server
Here is the source of the application:
private void ConnectToSQL() {
string connectionString = @"Data Source=" + textBox4.Text + "Initial Catalog=" + textBox1.Text +"User ID=" + textBox2.Text + "Password=" + textBox3.Text;
using (SqlConnection objSqlConnection = new SqlConnection(connectionString)) {
try {
objSqlConnection.Open();
objSqlConnection.Close();
MessageBox.Show("Connection is successfull");
} catch (Exception ex) {
MessageBox.Show("Error : " + ex.Message.ToString());
}
Please help me with this issue.
Thank you!
You have missed a semicolon(;)
in your connection string. If you append it in your connection string, it should work.
string connectionString = @"Data Source=" + textBox4.Text +
";Initial Catalog=" + textBox1.Text +
";User ID=" + textBox2.Text +
";Password=" + textBox3.Text;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다