Reputation: 3229
I am doing some research about connection to different databases. In Java, one can connect to a database using the JDBC Driver. I was researching about the connection of the SQL Server database through C# through the SqlConnection
object using this code:
SqlConnection cnn = new SqlConnection("Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password");
Is any driver used in this scenario, or is it just the "SqlConnection" that handles all the work by providing a "ConnectionString"?
Upvotes: 0
Views: 200
Reputation: 216363
ADO.NET is a set of common classes and interfaces used by every net program to interact with every kind of databases.
ADO.NET provides a set of built-in classes in the namespace System.Data.SqlClient to connect to a SqlServer database, also a set of classes (rather obsolete) for Oracle and a set of classes for generic OLEDB and ODBC driver each of them in their own namespace. The NET framework, installed on the client computer contains everything that is necessary to connect to SqlServer.
Other vendors have built specific ADO.NET providers using the same base classes and interfaces (MySql, the Oracle own ODP.NET provider, SQLite and so on...), of course you need to install these files downloading from the vendor site with any required software to connect to their databases.
The basic concepts of interaction with ADO.NET are:
And this is the basic picture. As you can see, a simple answer cannot cover this broad subject, so a bit of research is required.
Here a very simple example
string cmdText = "INSERT INTO Customers (Name, Address) VALUES (@name, @address)"
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
command.Parameters.AddWithValue("@name", "Steve");
command.Parameters.AddWithValue("@address", "Stackoverflow Street, 42");
command.Connection.Open();
command.ExecuteNonQuery();
}
Upvotes: 2