Database Code
  Home arrow Database Code arrow Page 3 - A Closer Look at ADO.NET: The Connection O...
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE CODE

A Closer Look at ADO.NET: The Connection Object
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 25
    2005-07-26

    Table of Contents:
  • A Closer Look at ADO.NET: The Connection Object
  • The Example
  • The ConnectionString Property Setting
  • Common Errors While Connecting
  • Using VS.NET to Create a SqlConnection Object

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    A Closer Look at ADO.NET: The Connection Object - The ConnectionString Property Setting


    (Page 3 of 5 )

    The Connection String value is used to provide information to connect to a specific SQL server instance. This information includes the server name, database name, the authentication mechanism, and some other important information such as connection timeout and network settings. You specify this type of information as a string value containing pairs of key/value separated by a semicolon (;). The order of listing these pieces of information is not critical; also, you can choose any capitalization you may like. Let's discuss some of the most important and commonly used Connection String Information.

    Server: This is the name of the database server instance. Use (local) if the server is on your machine, so the Connection String will look like SqlConn1.ConnectionString = "Server=(local);Database=pubs;Integrated Security=true". I have used the server name MichaelServer because this is the server instance name on my machine, which is also called MichaelServer. To access a SQL server instance on your network, you need to qualify the instance name with the machine name. For example, if the machine is called MickMachine and the server is called MichaelServer, you set MickMachine\MichaelServer to the server. But most of the time you will find that both the machine name and the server name have the same value, and that's all you have to set.

    Connection Timeout: The connection timeout is how many seconds the connection waits to establish the connection with the server before generating an error. The default value is 15 seconds. You can read the connection timeout (after you set it here in the connection string) through the ConnectionTimeOut property of a SqlConnection object.

    Database: The database that will be used by the connection to issue commands.

    Integrated Security: SQL Server uses two different ways to authenticate users. The first way is to use NT authentication in which SQL Server uses your Windows login to access the server (your Windows login must be authorized to access SQL Server in this case). The other way is to use SQL Server authentication, which can be set in the connection string using the next two keys. The integrated security key has the default value of false, which means that it will not be used to connect to the SQL Server, so if you want use it you have to set it to true as we did in our example.

    User ID: This is the SQL Server user ID that will be used when you want to access the server using SQL Server authentication.

    Password: The password that's associated with the server user ID. If it's an empty password you can use it as in the following Connection String, "Server=(local);Database=pubs;User ID=sa;Password=;"

    More Database Code Articles
    More By Michael Youssef


     

    DATABASE CODE ARTICLES

    - Deployment of the MobiLink Synchronization M...
    - MobiLink Synchronization Wizard in SQL Anywh...
    - Finding Matching Records in Data Access Pages
    - Using the AccessDataSource Control in VS 2005
    - A Closer Look at ADO.NET: The Command Object
    - A Closer Look at ADO.NET: The Connection Obj...
    - Using ADO to Communicate with the Database, ...
    - Code Snippets: Counting Records
    - Constraints In Microsoft SQL Server 2000
    - Multilingual entries into a DB and to be dis...
    - Getting A List of Tables From SQL Server
    - SQL Server Database Creator - .NET Version
    - ADO Recordset Paging
    - Two combos, one textbox example
    - Discussion & Listserv Module by Mike Eck...

    Iron Speed




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway