ADO.NET SQL Server Connection
Microsoft .NET Framework Data Provider for SQL Server proves to be a valuable tool. The initial step in connecting the application to the database involves creating an instance of the Server object and establishing a connection with the SQL Server instance.
SqlConnection Object
In VB.Net, the SqlConnection Object serves as the primary component responsible for handling the physical communication between the application and the SQL Server database. This object is part of the .NET Framework's Data Provider for SQL Server Database, providing the necessary functionality to establish, manage, and interact with the database.
To create an instance of the SqlConnection class in the .NET Framework, developers need to provide a connection string as an argument, which contains essential information such as the server name, database name, credentials, and any additional settings required for the connection. This connection string is passed to the constructor of the SqlConnection class, enabling the creation of the SqlConnection instance.
Once the SqlConnection instance is established and the connection is successfully made to the SQL Server database, developers can utilize SQL commands to execute queries, updates, or stored procedures, using the capabilities of the Connection Object. These SQL commands allow for data retrieval, manipulation, or any other required operations within the database.
Sql Server connection string
If you have a named instance of SQL Server, you'll need to add that as well.
The Close() method in SqlConnection class is used to close the Database Connection. The Close method rolls back any pending transactions and releases the Connection from the SQL Server Database.
A Sample VB.Net Program that connect SQL Server using connection string.
Connecting to SQL Server using windows authentication
Trusted Connection from a CE device
This will only work on a CE device
Connect via an IP address
1433 is the default port for SQL Server.
A sample VB.Net program that demonstrate how to execute sql statement and read data from SQL server.
A sample VB.Net program that perform Data Manipulation tasks like Insert , Update , Delete etc. also perform by the ExecuteNonQuery() of SqlCommand Object.
Full Source VB.NET- ADO.NET ExecuteNonQuery in SqlCommand Object
- ADO.NET ExecuteNonQuery in OleDbCommand Object
- ADO.NET ExecuteScalar in SqlCommand Object
- ADO.NET ExecuteScalar in OleDbCommand Object
- ADO.NET ExecuteReader in SqlCommand Object
- ADO.NET ExecuteReader in OleDbCommand Object
- How to ADO.NET DataReader
- How to ADO.NET SqlDataReader
- How to ADO.NET OleDbDataReader
- How to Multiple Result Sets in ADO.NET
- Getting Schema Informations from SqlDataReader
- Getting Schema Informations from OleDbDataReader
- What is DataAdapter
- What is SqlDataAdapter
- What is OleDbDataAdapter
- Vb.NET ExecuteReader and ExecuteNonQuery