Login Error - DataContextFactory seems to be not working RRS feed

  • Question

  • Hi Folks, I' still learning this issues, I need your help.

    I' trying to login in my application, that was working, but I had to install an SSD Driver, and I lost my everything that was working. I had to install a new SQLServer, and everything else.

    I have a File.DAL, which uses DataContextFactory and a file .dbml, to create a connection.

    However the connection is not working or my code is wrong.

    Can you guys help me with that please.

    The Error message is 

    System.NullReferenceException: 'Object Reference not definide for an instance ...'

    Sorry for the Portuguese. This is the first one. All the others will be in English.

    namespace SGFRenaissance { public partial class Login : Form { String usuario, pwd; public bool logado = false; public Login() { InitializeComponent(); } public static class DadosGerais { public static string Loginusuario; } public void EfetuarLogin() { usuario = nome_LoginTextBox.Text; pwd = senha_UsuarioTextBox.Text; DadosGerais.Loginusuario = usuario; // pgto = txt_pgto.Text; var user = DataContextFactory.dataContext.Usuarios.Count(x => x.Login_Name == nome_LoginTextBox.Text && x.Senha_Usuario == senha_UsuarioTextBox.Text);

    // Error is on this line above. if (user > 0) { this.logado = true; this.Dispose(); } else { MessageBox.Show("Usuário ou Senha incorretos!"); } } private void btn_efetuarlogin_Click(object sender, EventArgs e) { EfetuarLogin(); } private void btn_cancelar_Click_1(object sender, EventArgs e) { Application.Exit(); } private void btn_efetuarlogin_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) EfetuarLogin(); } private void Login_Load(object sender, EventArgs e) { #if DEBUG nome_LoginTextBox.Text = "Lucas"; senha_UsuarioTextBox.Text = "1234"; #endif } } }

    Friday, January 7, 2022 6:42 PM