Jag har skrivit en connection till sql från visual studio, får ett exception fel
"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."
Förstår inte vad felet är och hur jag fixar det?
"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."
Förstår inte vad felet är och hur jag fixar det?
Kod:
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; } } }