This class provides a connection to an Sql Server database.
We need to pass Connection String as Parameter when creating SqlConnection Object.
The Connection String contains all the information required to open a connection to your database.
If we are not passing it as Parameter, then we can pass it using property such as:
SqlConnection.ConnectionString="Data Source=PC\SQLEXPRESS; Initial Catalog=college; User ID=sa; Password= 123; Integrated Security=TRUE"
Data source:-In this parameter, we specify the name of the database server ie,SQL Server that you want to access. Usually the PC name on which the SQL Server is installed.Initial Catalog:- In this parameter, we specify the name of the database to which you want to connect. UserID and Password(Optional) Integrated Security:- This parameter is used to specify certain security measures. Default value is set to TRUE. Example:-
Data Source=PC\SQLEXPRESS; Initial Catalog=college ;User ID=sa; Password=123
Dim x As SqlConnection=New SqlConnection("Data Source=PC\SQLEXPRESS ;Initial Catalog=college; User ID=sa;Password=123")
Opening and Closing the Connection:-After passing the Connection String as Parameter we are ready to establish connection with the database, for this we will use Open() method which is defined in the SqlConnection Class such as:-x.Open()
Open() method will open the connection, similarly we can also close the connection after we have performed the desired task with the connectionX.Close()
This method is also defined in the SqlConnection class.