Using Sql server you can perform many kind of operations but before this you need a connection. To create a connection, you need to specify a value for its ConnectionString property. This ConnectionString defines all the information the computer needs to find the data source, log in, and choose an initial database. Consider the following two examples, the first one shows the connection with Sql Server database using OleDb:
Dim SQLConn As New OleDbConnection
SQLConn.ConnectionString = "Provider=SQLOLEDB.1;" _ & "Password=YourPassword;Persist Security Info=True;" _ & "User ID=YourUserID;Initial Catalog=YourDatabaseName;" _ & "Data Source=NameOfSQLServer"
The second example shows the connection with Sql server database using SqlClient. Here we use the SqlConnection object:
Dim strConn As String = "Server=localhost;UID=YourUID; " _ & "Password=YourPassword;Database=YourDatabaseName"
Dim SQLConn As New SqlClient.SqlConnection(strConn)
In above two examples you have seen a series of distinct pieces of information, separated by semicolon (;). The description of these pieces of information is as follows:
Provider: This is the name of the OleDb provider, which allows communication between ADO.Net and your database. This must be specified because it tells the OleDb the type of database with which you want to connect.
Data Source: This indicates the name of the server where the data source is located. Notice if the server is on the same computer hosting the ASP.Net site the writing “localhost” is sufficient.
Initial Catalog: This is the name of the database that this connection will be accessing. It’s only the “initial” database because you can change it later, by running a Sql command or by modifying the database property.
User ID (UID): This is used to access the database. The “UID” is alternative to User ID.
Password (Pwd): This applies to the Sql Server Authentication only. “Pwd” is an alternative to “Password”.
Connection Timeout: This determines how long your code will wait, in seconds, before generating an error if it cannot establish a database connection.
Initial Catalog (Database): This indicates the name of the database with which we want to connect. “Database” is an alternative to the “initial catalog”
Trusted_Connection: Contains two values yes or no. Setting to “Yes” enables Windows NT Authentication.