Exception Error:

private void Form1_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=LINLINPC\\SQLEXPRESS;Initial Catalog=POS;Integrated Security=True";
            conn.Open();
            MessageBox.Show("Connection");
            conn.Close();
         }

I got this error(The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.)

When you installed SqlExpress did you select Mixed authentication or windows Authentication?

Can you connect to your sql DB with Sql Server Management Studio?

if you can what does it say.

Look at the screenshot.

This would is my SQlConn

SqlConnection SqlConn = new SqlConnection(@"Data Source=SAVR\SQLEXPRESS;Initial Catalog=ShopDB;MultipleActiveResultSets=True;User Id=sa;Password=*******;");

if solved please mark as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.