Professional Documents
Culture Documents
System - Data.Dll System - XML.DLL.: Sqlconnection Constructors
System - Data.Dll System - XML.DLL.: Sqlconnection Constructors
System - Data.Dll System - XML.DLL.: Sqlconnection Constructors
NET overview
ADO.NET Introduction
All the ADO.NET classes are located into System.Data.dll and integrated with XML
classes located into System.Xml.dll.
ADO.NET has two main components that are used for accessing and manipulating data
are the .NET Framework data provider and the DataSet.
It is used to establish an open connection to the SQL Server database. It is a sealed class
so that cannot be inherited. SqlConnection class uses SqlDataAdapter and SqlCommand
classes together to increase performance when connecting to a Microsoft SQL Server
database.
Connection does not close explicitly even it goes out of scope. Therefore, you must
explicitly close the connection by calling Close() method.
SqlConnection Signature
1. public sealed class SqlConnection : System.Data.Common.DbConnection, ICloneable, I
Disposable
SqlConnection Constructors
Constructors Description
Method Description
ChangePassword(String, It changes the SQL Server password for the user indicated in the
String) connection string.
SqlConnection Example
Now, let's create an example that establishes a connection to the SQL Server. We have
created a Student database and will use it to connect. Look at the following C# code.
// Program.cs
1. using System;
2. using System.Data.SqlClient;
3. namespace AdoNetConsoleApplication
4. {
5. class Program
6. {
7. static void Main(string[] args)
8. {
9. new Program().Connecting();
10. }
11. public void Connecting()
12. {
13. using (
14. // Creating Connection
15. SqlConnection con = new SqlConnection("data source=.; database=student;
integrated security=SSPI")
16. )
17. {
18. con.Open();
19. Console.WriteLine("Connection Established Successfully");
20. }
21. }
22. }
23. }
Output:
ADO.NET SqlCommand Class
This class is used to store and execute SQL statement for SQL Server database. It is a
sealed class so that cannot be inherited.
SqlCommand Signature
1. public sealed class SqlCommand : System.Data.Common.DbCommand, ICloneable, IDi
sposable
Constructors
Constructor Description
Methods
Method Description