Introduction : This Tutorial section enable you to learn the basic concept needed for creating Connection Object.
Introduction :-
The Connection Component of a data provider is used to establish a connection with a data source. To Move data between a data source and a client application, you must first create a connection object and then provides a connection string for this object. To connect a Microsoft SQL server database, you use the SqlConnection class for the Connection.
The Following list displays the commonly used properties and methods of SDqlConnection class
ConnectionString Property: - It provides information, such as the data source and database name, that is used to establish connection with a database. Open() :- it opens a database connection with the property settings specified by the ConnnectionString property. Close() method :- It closes the connection to the database.
The ConnectionString property provides the Information that defines a Connection to a database by using a string of parameters.
The Following table describes the various parameter of the connection string.
Provider :- it is sued to return the name of the provider for tha connections. Initial Catalog :- it is used to specify the name of the database. Data Source :- it is used to specify the name of the server to be used when a Connection is open. User ID :- it is used to specify the server login account. Password: - it is used to specify he login password for the server login account. Integrated Security :- It is used to determine whether or not the connection needs to be a secure connection. When false the user ID and password are specified in the connection. When true, the current windows account credentials are used for authentications Recognized values are true, false, yes , no and SSPI(Security Support Provider Interface) which is equivalent to true. For Example :-
In C# SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source =.;Initial Catalog =AdventureWorks;uid =sa; pwd = yourpassword";
//uid = userId and pwd = Password and Adventureworks is a database name.
In vb.Net Dim con As New SqlConnection()
con.ConnectionString = "Data Source =.;Initial Catalog =AdventureWorks;uid =sa; pwd = yourpassword" In the preceding code Provider and Integrated Security
parameter of Connection String property
is not used. As the object of the sql server
would be used as the default Provier. The value for integrated Security
parameter has not been provided because
the value of user ID and Password parameter of ConnectionString is already
assigned.
Note :- To use the Functionality of the SQlConnection class,
a System.Data.SQLClient namespace should be included. It is a Collection of
classes to access a SQL server Database.
|