When trying to connect to sql through sqlconnection I get an error, "NullReferenceException was unhandled" "An unhandled exception of type 'System.NullReferenceException' occurred in DBLabControllers.dll
Additional information: Objektreferensen har inte angetts till en instans av ett objekt."
Why do I get exception fail and how do I fix it?
Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Data; using System.Windows.Forms; namespace DBLabs { public class DBConnection : DBLabsDLL.DBConnectionBase { public DBConnection() { string connectionString = null; SqlConnection connection; connectionString = "Data Source=(local);Initial Catalog=www3.idt.mdh.se;User ID=ezi15001;Password=********"; connection = new SqlConnection(connectionString); } public override bool login(string username, string password) { string constring = "Data Source = www3.idt.mdh.se;" + "Database=" + username + "_db;" + "User ID=" + username + ";" + "Password=" + password; SqlConnection myConnection = new SqlConnection(constring); try { myConnection.Open(); } catch (Exception) { myConnection.Close(); return false; } finally { myConnection.Close(); } return true; } }