I am trying to connect to a SQL Server 2005 Express edition remotely using c#, but it is throwing an exception.
A network related or instance specific error occured while establishing a connection to SQL Server .The server was not found or was not accessible.Verify that the instance name is correct and the SQL Server is configured to allow remote connection. (provider :Name Pipes Provider,error:40 - Could not open a connection to SQL Server)
Below is the code I am using to connect to the database
private void button_test_Click(object sender, EventArgs e)
{
try
{
string str = "data source=" + textBox_server.Text + "; initial catalog=" + textBox_db.Text
+ "; user id=" + textBox_user.Text + "; pwd=" + textBox_password.Text + ";";
SqlConnection sqlcon = new SqlConnection(str);
sqlcon.Open();
sqlcon.Close();
MessageBox.Show("Test Connection was successfull");
}
catch (Exception ex)
{
MessageBox.Show("Test Connection failed. "+ ex.Message);
}
I am entering the correct ip, database table name, username and password.
Verified everything in the SQL Server Express configurations. Everything is fine.
So where am I going wrong?