Could not load file or assembly 'System.Data.SqlClient,...'

1

I'm having trouble using system.data.sqlclient namespace. I have made a very simple console application to save entered data in database. Need help regarding this, please help. I have attached screenshot of console.

using System;
using System.Data.SqlClient;

namespace StudentDetails_Proj
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Name:");
            string name = Console.ReadLine();
            Console.WriteLine("Enter Age:");
            string age = Console.ReadLine();
            Console.WriteLine("Enter Id:");
            string id = Console.ReadLine();
            Console.WriteLine("Enter Address:");
            string address = Console.ReadLine();
            // string connectionstring = "Server=G2W9DRV2E;Database=UserLogin;User Id=sa;Password=Password1";
            string connectionstring = "Server=G2W9DRV2E;Database=UserLogin;Integrated Security=true";
            SqlConnection connection = new SqlConnection(connectionstring);
            connection.Open();
            string cmdText = string.Format("Insert into StudentInfo values('{0}',{1},{2},'{3}')", name, age, id, address);
            SqlCommand cmd = new SqlCommand(cmdText, connection);
            cmd.ExecuteNonQuery();
            connection.Close();

        }
    }
}

I'm getting this error message:

Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'System.Data.SqlClient, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)

System.BadImageFormatException: Cannot load a reference assembly for execution

c#
sql-server
sqlclient
asked on Stack Overflow Aug 9, 2019 by Vishal Gupta • edited Aug 9, 2019 by marc_s

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0