none
SqlException wash unhandled RRS feed

  • Question

  • //I created the Login to SQL Database file using C#. when Running the program displayed, Sql exeption unhandled.

    "An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll"

    I wish others would give me sollution of this. Thanks you

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.Sql;
    using System.Data.OleDb;
    using System.Data.SqlClient;

    namespace ITSI_LOGING
    {
        public partial class Form1 : Form
        {
            SqlConnection con = new SqlConnection();
            public Form1()
            {
                SqlConnection con = new SqlConnection();
                con.ConnectionString = @"Data Source=(LocalDB)\v11.0;Initial Catalog=Db1ITSI;Integrated Security=True;Pooling=False";
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;Initial Catalog=Db1ITSI;Integrated Security=True;Pooling=False");
                con.Open();

                {
                }
            }

            private void button1_Click(object sender, EventArgs e)
            {
                SqlConnection con = new SqlConnection();
                con.ConnectionString = @"Data Source=(LocalDB)\v11.0;Initial Catalog=Db1ITSI;Integrated Security=True;Pooling=False";
                con.Open();
                string userid = textBox1.Text;
                string password = textBox2.Text;
                SqlCommand cmd = new SqlCommand("select userid,password from Login where userid='" + textBox1.Text + "'and password='" + textBox2.Text + "'", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    MessageBox.Show("Login sucess Welcome to Homepage");
                    System.Diagnostics.Process.Start("autonics");
                }
                else
                {
                    MessageBox.Show("Invalid Login please check username and password");
                }
                con.Close();

            }

            private void button2_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }
        }
    }

    Friday, April 7, 2017 4:51 PM

All replies

  • Hi ITSI.PT,

    Welcome to MSDN forum.

    This forum is to discuss the VS IDE, as your issue is more related to the ADO.NET Managed Providers, I will move it to ADO.NET Managed Providers forum for suitable support.

    If you have some issue on VS IDE, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Monday, April 10, 2017 8:23 AM
  • It would add a Try...Catch block to your code and display the details of the exception message.

            try
            {            
                // your code
            }
    
            catch (Exception e)
            {
                // display exception
                Console.WriteLine("{0} Exception caught.", e);
            }


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, April 11, 2017 12:21 PM