When I try to open a connection to the database I hit an error
"Object reference not set to an instance of an object."
I have make a simple test connection function same error coming out when open connection as the line in red. Here my function:
Code:
private void butConnect_Click(object sender, System.EventArgs e)
{
SqlConnection connect = null;
try
{
connect = new SqlConnection();
connect.ConnectionString = "Data Source=(local);Initial Catalog=DB;User ID=sa;Password=password";
connect.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
My program is in .NET 1.1. Dunno why the error occur, it work fine previously. Thank you for someone help.