locked
Drivers used to connect to SQL Server RRS feed

  • Question

  • Hi,

    Can someone please let me know the drivers used by the following data provider to connect to SQL Server

    SqlConnection()

    OdbcConnection()

    OleConnection()

    By drivers I mean: ODBC Driver, SQL Native Client (SNAC) etc...

    Best regards

    Tuesday, January 22, 2019 5:46 PM

Answers

  • Hi S Rym,

    Thank you for posting here.

    For your question, the SqlConnection deals directly with SQL Server, the OleDbConnection requires an OLEDB provider for the database to which you want to connect, while the OdbcConnection requires an ODBC driver for the database.

    SqlConnection()

      SqlConnection con;
            SqlCommand cmd;
                con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + @"Database.mdf;" + "Integrated Security=True");
                con.Open();
                cmd = new SqlCommand("select Image from Image", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);

    OdbcConnection()

    string queryString = 
                  "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')";
    	OdbcCommand command = new OdbcCommand(queryString);
    
    	using (OdbcConnection connection = new OdbcConnection(connectionString))
    	{
    		command.Connection = connection;
    		connection.Open();
    		command.ExecuteNonQuery();
    
                  // The connection is automatically closed at 
                  // the end of the Using block.
    	}

    OleConnection()

     string strDSN = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = Database1.accdb";
                string strSQL = "SELECT * FROM Table1";
                // create Objects of ADOConnection and ADOCommand  
                OleDbConnection myConn = new OleDbConnection(strDSN);
                OleDbDataAdapter myCmd = new OleDbDataAdapter(strSQL, myConn);
                //myConn.Open();
                DataSet dtSet = new DataSet();
                myCmd.Fill(dtSet, "Table1");
                DataTable dTable = dtSet.Tables[0];

    Best Regards,

    Wendy


    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.

    • Marked as answer by S Rym Friday, January 25, 2019 9:07 PM
    Wednesday, January 23, 2019 6:34 AM
  • Hello,

    In regards to reference DLL's, the highlighted in yellow is what's needed for accessing data for SqlClient connection, OleDb connection and Odbc connection. Select references in a standard project, single click say System.Data and note the path.

    So on my computer the path is under Framework v4.6.1, depending on the version of the Framework you have installed it may be different.

    So for working with SqlConnection the base DLL is System.Data.SqlClient

    Possible paths

    In regards to ODBC drivers, although not an exact answer check out the following page.

    In closing, System.Data is the main entry point but also look at the following under the path mentioned above.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by S Rym Friday, January 25, 2019 9:07 PM
    Thursday, January 24, 2019 11:28 AM
  • Since WinXP SP2, the MDAC has became part of standard Windows installation, so there is no need to worry about ODBC, OLEDB, etc. drivers.

    However you may need SQL native client to use SqlConnection. Use the link I provided to download the native client for SQL 2012, or just install the "Client Tools" on your SQL Server installation disc to install it. That should enable you to connect anything SQL2008 or later.


    • Edited by cheong00Editor Friday, January 25, 2019 3:50 AM
    • Marked as answer by S Rym Friday, January 25, 2019 9:07 PM
    Friday, January 25, 2019 3:47 AM
    Answerer

All replies

  • Hi S Rym,

    Thank you for posting here.

    For your question, the SqlConnection deals directly with SQL Server, the OleDbConnection requires an OLEDB provider for the database to which you want to connect, while the OdbcConnection requires an ODBC driver for the database.

    SqlConnection()

      SqlConnection con;
            SqlCommand cmd;
                con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + @"Database.mdf;" + "Integrated Security=True");
                con.Open();
                cmd = new SqlCommand("select Image from Image", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);

    OdbcConnection()

    string queryString = 
                  "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')";
    	OdbcCommand command = new OdbcCommand(queryString);
    
    	using (OdbcConnection connection = new OdbcConnection(connectionString))
    	{
    		command.Connection = connection;
    		connection.Open();
    		command.ExecuteNonQuery();
    
                  // The connection is automatically closed at 
                  // the end of the Using block.
    	}

    OleConnection()

     string strDSN = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = Database1.accdb";
                string strSQL = "SELECT * FROM Table1";
                // create Objects of ADOConnection and ADOCommand  
                OleDbConnection myConn = new OleDbConnection(strDSN);
                OleDbDataAdapter myCmd = new OleDbDataAdapter(strSQL, myConn);
                //myConn.Open();
                DataSet dtSet = new DataSet();
                myCmd.Fill(dtSet, "Table1");
                DataTable dTable = dtSet.Tables[0];

    Best Regards,

    Wendy


    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.

    • Marked as answer by S Rym Friday, January 25, 2019 9:07 PM
    Wednesday, January 23, 2019 6:34 AM
  • Hello,

    In regards to reference DLL's, the highlighted in yellow is what's needed for accessing data for SqlClient connection, OleDb connection and Odbc connection. Select references in a standard project, single click say System.Data and note the path.

    So on my computer the path is under Framework v4.6.1, depending on the version of the Framework you have installed it may be different.

    So for working with SqlConnection the base DLL is System.Data.SqlClient

    Possible paths

    In regards to ODBC drivers, although not an exact answer check out the following page.

    In closing, System.Data is the main entry point but also look at the following under the path mentioned above.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by S Rym Friday, January 25, 2019 9:07 PM
    Thursday, January 24, 2019 11:28 AM
  • Since WinXP SP2, the MDAC has became part of standard Windows installation, so there is no need to worry about ODBC, OLEDB, etc. drivers.

    However you may need SQL native client to use SqlConnection. Use the link I provided to download the native client for SQL 2012, or just install the "Client Tools" on your SQL Server installation disc to install it. That should enable you to connect anything SQL2008 or later.


    • Edited by cheong00Editor Friday, January 25, 2019 3:50 AM
    • Marked as answer by S Rym Friday, January 25, 2019 9:07 PM
    Friday, January 25, 2019 3:47 AM
    Answerer
  • Thanks all for your reply, things are pretty clear for me now
    Friday, January 25, 2019 9:09 PM