The connection object is at the top level and is the gateway to all data requests
Database connection Process
SqlConnection theconnection = new SqlConnection (); Create an object instance of connection theconnection.connectionstring = "server=.; integrated security=true; "; Set its connection string, local area Connection, integrated secure connection //Before the connection string is passed as a parameter to the code that creates the Connection object instance, it is a good idea to assign it to a string //string connectionstring = "Server =.; integrated security=true; "; SqlConnection theconnection=new SqlConnection (connectionstring); The connection string is passed as a parameter to the Create connection " Theconnection.open (); if (theconnection.state = = System.Data.ConnectionState.Open) Console.WriteLine ("Database connection is Open");
SqlClient data provides another way to construct a connection string that uses the SqlConnectionStringBuilder object
The benefit of using SqlConnectionStringBuilder is that an exception is thrown when an invalid connection string is entered
Three ways to specify the properties of a connected data source
1 specifying the connection string through the ConnectionString property of the Connection object
2 passing the connection string into the constructor of the connection object
3 using the Data Source Configuration Wizard
ADO (1)